After creating my middleware I get multiple redirects in my Laravel app, There is definitely something I am doing wrong but I don't know where.
public function handle($request, Closure $next)
{
$route = Route::currentRouteName();
if($route!= "dashboard" || $route != "verify.again")
{
if(! is_null($request->user()) && ! $request->user()->verified) {
return redirect()->route("verify.again");
}
elseif(!$request->user()->mobile){
return redirect()->route("verify.again");
}
else{
return $next($request);
}
}
return $next($request);
}
Controller
public function index(){
$user = Auth::user();
if(!$user->verified)
{
return view("dashboard.verification.index", ["verify"=>"email", ]);
}
elseif(!$user->mobile)
{
return view("dashboard.verification.index", ["verify"=>"mobile", ]);
}
return view("dashboard.usermaster");
}