最佳答案
看了一下Horizon
的源码,他的中间件里面,如果不满足条件就直接abort(403)
了,所以按我说的那种确实也会进入Horizon
public function handle($request, $next)
{
return Horizon::check($request) ? $next($request) : abort(403);
}
所以可以在auth
方法里面手动抛出AuthenticationException
,这样就可以跳转到登录界面了
Horizon::auth(function ($request) {
throw new AuthenticationException();
});
讨论数量:
文档写的简单,但是够用了啊
Horizon::auth(function ($request) {
// 在这里你可以根据需求自己判断啊
// 比如判断用户类型
if($request->user()->isAdmin()){
return true;
}
// 或者
if(Auth::user()->isAdmin()){
return true;
}
// 或者
if(Auth::user()->email === 'xxxxx@xxx.xxx'){
return true;
}
return false;
});
看了一下Horizon
的源码,他的中间件里面,如果不满足条件就直接abort(403)
了,所以按我说的那种确实也会进入Horizon
public function handle($request, $next)
{
return Horizon::check($request) ? $next($request) : abort(403);
}
所以可以在auth
方法里面手动抛出AuthenticationException
,这样就可以跳转到登录界面了
Horizon::auth(function ($request) {
throw new AuthenticationException();
});
推荐文章: