Notification instead of 403 error page
Hi everyone!
As I'm working with roles and permissions, I have a lot of action that can and cannot be done depending on the user and its role.
Is it possible to get that, instead of triggering a 403 error (from a gate or other policy), a notification with the message "Unauthorized" is triggered?
I imagine it can be done by managing Notifications in the various actions, but I would prefer to write it once and have it work for all cases.
Thank you very much for the support!
7 Replies
You can intercept it and redirect back to the homepage say and fire out the notification error 403 etc
Hi toeknee, thank you for the reply!
Where would you code it?
would it not be better to just hide the buttons if the user can't perform the action?
It is talked about here:
https://laracasts.com/discuss/channels/laravel/how-to-catch-403-error-to-show-a-flashy-message
AS AWCodes says, you would be better to auth()->user()->can()
Hi! Yeah, that is the next step. But I'd like to avoid people from forcing its way through the uri.
But feel free to tell me if it does make sense or not π
Yea, but a policy would handle the uri anyway, right. And the same policy could be used to show or hide the button too.
Got it! Thank you so much for your time!