This is the documentation for
v4 but the latest version is
v5
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-permission
If you need to override exceptions thrown by this package, you can simply use normal Laravel practices for handling exceptions.
An example is shown below for your convenience, but nothing here is specific to this package other than the name of the exception.
You can find all the exceptions added by this package in the code here: https://github.com/spatie/laravel-permission/tree/master/src/Exceptions
app/Exceptions/Handler.php
public function register()
{
$this->renderable(function (\Spatie\Permission\Exceptions\UnauthorizedException $e, $request) {
return response()->json([
'responseMessage' => 'You do not have the required authorization.',
'responseStatus' => 403,
]);
});
}