php - 检查中间件中的状态是否处于活动状态
问题描述
我有一个名为的表agents
,我想在middleware
代理尝试登录时签入,代理是否处于活动状态
public function handle($request, Closure $next)
{
$user = $this->auth->user();
if(agentmodel::where('status') == 'active'){
true;
}else{
false;
}
}
解决方案
您必须在中间件中返回请求才能继续
public function handle($request, Closure $next)
{
// Declared but not used
$id = auth()->id();
// If agent belongs to a user
if (App\agentmodel::where('user_id', $id)->first()->status == 'active') {
return $next($request);
}
\Session::flush();
return back()->with('error', 'Your account is not active');
}
如果代理不活动,这将重定向回来并且不允许用户继续
推荐阅读
- c# - 账户之间的 EWS 扩展属性
- android - 片段不更新 ViewPageAdapter
- spring - Spring CRUD 应用程序:Servlet [dispatcherServlet] 的 Servlet.service():java.lang.NullPointerException]
- r - dplyr 中的函数和非标准评估
- visual-studio - 如何添加不属于代码库的“评论”?
- python - Python - Lark - 语法 - 无法生成 AST
- hadoop - Hortonworks HDP 3:启动 ResourceManager 时出错
- sql - 如果我想将两个不同表中的 2 个值相乘,我应该在迁移中输入什么?ASP.NET MVC 实体框架
- javascript - 如何在 Javascript 中设置循环迭代之间的延迟?
- html - 可以将元素强制到隐式网格的最后一行吗?