When a user access a page they don't have access to an Spatie \ Permission \ Exceptions \ is thrown, is there a recommended way to handle these?
User does not have the right roles.
Ideally being able to redirect the user and a message would be useful.
Figured it out by adding my handling inside app/Exceptions/Handler.php
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
flash($e->getMessage(), 'danger');
return back();
}
return parent::render($request, $e);
}
Most helpful comment
Figured it out by adding my handling inside app/Exceptions/Handler.php