How to Redirect Unauthorized Users | This action is unauthorized Laravel Policy

How to Redirect Unauthorized Users | This action is unauthorized Laravel Policy

The problem in Laravel is it doesn’t redirect unauthorized users to a specific page but just throw an exception to the user, to redirect to 403 custom forbidden page you have to edit the laravel by default code.

Possible Solution 1 – Redirect Unauthorized Users Laravel

 

Please navigate to the App\Exceptions\Handler.php and open the Handler.php file.

And use Authentication Exception Class at the top.

 

 

Now scroll down to the public function render($request, Exception $exception) function

 

Final Words – This Action is Unauthorized Laravel

That’s it. You don’t need to do anything else. Redirect the user from the route using middleware. If you still have a question please ask in the comment we will try our best to keep in touch with you.