使用中间件,须要注册,基本用法查看官方文档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); }