Skip to content

Commit

Permalink
[Docs] Include Laravel 11 example in exceptions.md (#2768)
Browse files Browse the repository at this point in the history
* include a documentation for customizing  exception in laravel 11

---------

Co-authored-by: Chris Brown <code@drbyte.dev>
  • Loading branch information
frankliniwobi and drbyte authored Nov 27, 2024
1 parent 4981e71 commit 52119a1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/advanced-usage/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: Exceptions
weight: 3
---

If you need to override exceptions thrown by this package, you can simply use normal [Laravel practices for handling exceptions](https://laravel.com/docs/10.x/errors#rendering-exceptions).
If you need to override exceptions thrown by this package, you can simply use normal [Laravel practices for handling exceptions](https://laravel.com/docs/errors#rendering-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/main/src/Exceptions](https://github.com/spatie/laravel-permission/tree/main/src/Exceptions)


**app/Exceptions/Handler.php**
**Laravel 10: app/Exceptions/Handler.php**
```php

public function register()
Expand All @@ -23,3 +23,16 @@ public function register()
});
}
```

**Laravel 11: bootstrap/app.php**
```php

->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (\Spatie\Permission\Exceptions\UnauthorizedException $e, $request) {
return response()->json([
'responseMessage' => 'You do not have the required authorization.',
'responseStatus' => 403,
]);
});
}
```

0 comments on commit 52119a1

Please sign in to comment.