laravel中介軟體不能直接return

玫翠慧發表於2018-09-13

laravel中介軟體直接return 下邊的程式碼還是會執行

/**
* Class AdminAuthMiddleware
* @package Modules\Core\Http\Middleware
*/
class WebApiMiddleware
{
   /**
    * Handle an incoming request.
    *
    * @param  \Illuminate\Http\Request $request
    * @param  \Closure $next
    * @return mixed
    */
   public function handle($request, Closure $next)
   {
       if (Auth::guard("web")->guest()) {
           $data = ['code' => 401, 'data' => ['erroe' => '未登入'], 'msg' => '成功'];
           echo json_encode($data);exit;
       }

       return $next($request);
   }
}

複製程式碼

相關文章