thinkphp6 中间件

萝らか妹 提交于 2019-12-09 17:57:20

thinkphp6 中间件

使用中间件,需要注册,基本用法查看官方文档

https://blog.thinkphp.cn/1108963

中间价件只能返回 response对象

所以,要在中间件中直接返回信息,需要使用response对象.

路由中间件

比如路由中间件,权限验证功能。

public function handle($request, \Closure $next)
{
  $t = Request::post('token');
  if (!$t){
    // 直接返回信息
    return response()->data(json_encode(array('RS'=>1003,'Msg'=>'令牌错误')))->code(401);
  }
  return $next($request);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!