【问题标题】:Laravel $request->all() returning null inside the middleware handle functionLaravel $request->all() 在中间件句柄函数中返回 null
【发布时间】:2016-07-05 01:57:37
【问题描述】:

当我尝试在 handle() 函数中使用 $request->all() 时,我在 Laravel 5.2 中的 Auth 中间件返回 null。

这是我的路线声明:

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);
    }

  }

但是,当我在控制器中调用 $request->all() 方法时,它会返回数组 if 值。

我正在从客户端发送 JSON 请求。

请帮忙。

【问题讨论】:

  • 哇,抱歉,直到现在才看到它是中间件。但是如果发送了任何数据,它应该出现在 $request 中。您能否尝试添加一个获取请求以查看它之后是否仍然为空?只需将 '?key=value' 添加到您的地址即可。
  • “来自客户端的 JSON 请求”是什么意思,这里的客户端是什么意思?
  • 'Client'是这里的浏览器或者是通过另一个服务器的API调用。

标签: php laravel-5


【解决方案1】:

试试这个来访问参数:

$request->accountId

【讨论】:

    猜你喜欢
    • 2022-01-27
    • 2022-06-15
    • 2021-05-22
    • 2019-08-11
    • 2018-03-08
    • 1970-01-01
    • 2019-01-31
    • 2016-11-08
    • 2020-05-23
    相关资源
    最近更新 更多