【发布时间】: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调用。