简体   繁体   English

Laravel $ request-> all()在中间件句柄函数内返回null

[英]Laravel $request->all() returning null inside the middleware handle function

My Auth middleware in Laravel 5.2 is returning null when I am trying to use $request->all() inside the handle() function. 当我尝试在handle()函数中使用$ request-> all()时,Laravel 5.2中的Auth中间件返回null。

Here is my route declaration: 这是我的路线声明:

Route::group(['middleware' => ['web', 'auth.origin']], function () {

    Route::get('/', function () {
        return view('welcome');
    });

    Route::post('identity', ['uses' => 'IdentityController@create']);

});


  /**
   * Handle an incoming request. Authenticates a request to make sure
   * it's origin matches the allowed request origins.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  \Closure  $next
   * @return mixed
   */
  public function handle ($request, Closure $next)
  {
    dd($request->all()); die;
    return $next($request);

    $accountId = $request->input('accountId'); 
    if( in_array($accountId, self::$origin) ) {
      if( in_array($request->getHttpHost(), self::$origin[$accountId]) ) {
        return $next($request);
      }
    }
    else {
        return response('Unauthorized', 401);
    }

  }

However, When I am calling the $request->all() method inside my controller, it is returning the array if values. 但是,当我在控制器内调用$ request-> all()方法时,它将返回包含值的数组。

I am sending a JSON request from the client. 我正在从客户端发送JSON请求。

Please help. 请帮忙。

试试这个来访问参数:

$request->accountId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM