中间键

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');


posted @ 2019-07-09 15:09  同学文  阅读(171)  评论(0编辑  收藏  举报