Authorization in nested resource #52672
-
Hello, I'm facing an issue with the I have a resource called I also have 2 policies public function create(User $user, Talk $talk): bool
{
return $user->id === $talk->user_id ?
Response::allow() :
Response::denyAsNotFound();
} Since it's a nested resource, I want to deny users to create a question to a talk they do not own. But with the following rules in my public function create(Talk $talk)
{
Gate::authorize('question', $talk);
return Inertia::render('Questions/Create');
} The policy called is |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, I found a solution. I rename public function create(Talk $talk)
{
Gate::authorize('create', [Question::class, $talk]);
return Inertia::render('Questions/Create');
} I think, the documentation could contains more example of nested resource! |
Beta Was this translation helpful? Give feedback.
Ok, I found a solution.
I rename
TalkQuestionPolicy
toQuestionPolicy
to match the model name. Then, I pass the question class as first argument and then the talk.I think, the documentation could contains more example of nested resource!