使用中間件,須要註冊,基本用法查看官方文檔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); }