So in my laravel project i have 3 roles admin employee vendor and each have theyre controllers in the controllers i have put the middleware of the role it and it works no problem but i don't like the thing when a user dont have the role it gives HttpException error how i can change instead of giving the user HttpException redirect him back or to 404 not found page heres my controller
public function __construct()
{
$this->middleware('auth');
$this->middleware('role:employee');
}
Any small customization to exception handling can be done within the render() function of App\Exceptions\Handler. In this case you might do something like this ... inside that render function.
//change all 403's to 404's
if($exception->getCode() == 403){
throw new NotFoundHttpException();
}