Laraval Policies "This action is unauthorized" response message too long

Viewed 24

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!

1 Answers

Those are the debug information. Laravel applications show them when debug mode is enabled. You can disable it by changing APP_DEBUG=true to APP_DEBUG=false from the .env file in the laravel root directory.

Related