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);
}
来源:oschina
链接:https://my.oschina.net/u/3756690/blog/3139323