Answer the question
In order to leave comments, you need to log in
How to check the action in the policy on an unlogged user?
I'm in the view controller (I have a spa on vue.js) in the form of JSON I give some user rights, like this:
return [
'post' => $post,
'permissions' => [
'view' => auth()->user()->can('view', $post),
'edit' => auth()->user()->can('edit', $post),
'delete' => auth()->user()->can('delete', $post),
],
]);
?
then the policy can be checked for guests too . auth()->user()
will return null.
Answer the question
In order to leave comments, you need to log in
Stop using the Auth facade. Instead, use Gates, which is exactly what they are designed to solve your problem.
In the controller you need to use $this->authorize('update', $post) or constructor for resource controllers
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question