Reputation: 3835
I want to redirect the users to a page if they haven't confirmed their e-mail.
I can easily achieve that by doing this on the middleware:
if(Auth::user()->confirmed == 0)
{
return redirect("somewhereelse");
}
However I have 15 middlewares and I don't want to clutter them with this code.
Is there a way to apply such rule to the entire page where the user needs to be logged in without adding it to each middleware?
Upvotes: 1
Views: 106
Reputation: 194
I can suggest you 2 ways:
Edit your 'RedirectIfAuthenticated', if you have one, to
if(Auth::guard($guard)->check()) {
if(Auth::user()->confirmed == 0){
return redirect("somewhereelse");
}
return redirect('authenticatedarea');
}
You can check if user is logged in and, if it is, you can check if he verified email too with the same middleware.
Otherwise you can create another middleware just with this check.
I recommend the first one 'cause you can wrap 2 simple checks in one middleware... eventually you can split them later if you need to.
Upvotes: 2