php artisan make:middleware Checklogin(中间键名称)
注意group
public function handle($request, Closure $next,$paramas)
{
$tmpArr = explode('|',$paramas);
if(!in_array($request->route()->getName(),$tmpArr)){
if (!auth()->check()){
echo "<script>alert('请先登录!');location.href='login';</script>;";
}
}
//如果没有登陆成功,会调到登陆,需要用户输入用户名和密码进行验证
return $next($request);
}
//中间键判断
public function Layout(){
auth()->logout();
return redirect(route('login'))->with('msg','请重新登录');
}
//判断登录中间键
Route::get('/Layout','Home\HomeController@Layout')->name('Layout');