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);
}
相關文章
相關標籤/搜索