thinkphp6 中间件

thinkphp6 中间件

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

https://blog.thinkphp.cn/1108963thinkphp

中间价件只能返回 response对象json

因此,要在中间件中直接返回信息,须要使用response对象.post

路由中间件

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

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);
}
相关文章
相关标签/搜索