I'm using Laravel 8 for a personal project. I use Policy to manage who can do what. I have the view method in the policy like this:
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\User $passed
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, User $passed)
{
return $user->id == $passed->id;
}
When the policy returns error, so I can't view the user, the API response is not just "This action is unauthorized" but something like this:
{ "message": "This action is unauthorized.", "exception": "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException", "file": "C:\Users\fabri\Desktop\project\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php", "line": 387, "trace": [ with all trace here ] }
Why Laravel shows me all and not just "This action is unauthorized"?
Thank you so much for your attention!