vendredi 15 mai 2020

Laravel gates custom response

I am using Laravel 5.3 and i'm using gates to protect some routes. I want to be able to show a custom exception when unauthorised user tries to access the protected route. So instead of the default 500 response code "This action is unauthorized." I want to show my own custom exception message. How can I do it.

This is my gate

        Gate::define('superAdmin', function ($user) {
            return $user->hasRights('superadmin') ;
        });

How can i catch the exception if user is not a super admin and then show a custom message/response?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire