我所有的代碼都在Laravel 5.2上工作。現在我試着升級到Laravel 5.3,它在中間件上打破了。Laravel 5.3中間件請求合併不返回任何值
// Verify Middleware
public function handle($request, Closure $next)
{
// I already make sure the data is exists
$user = User::find('abc');
if (!$user) {
return responseHandler()->unauthorized('Unauthorized');
}
$request->merge(['user_id' => $user->id, 'device' => $device]);
return $next($request);
}
// User Controller
public function __construct(Request $request)
{
var_dump($request->all());
$this->user_id = $request->user_id;
$this->device = $request->device;
}
public function getProfile(Request $request)
{
$data = User::find($this->user_id);
$result = Fractal::item($data, new UserTransformer)->getArray();
return responseHandler()->success(0, $result, 'user');
}
問題是$this->user_id
始終爲空。但如果我從getProfile函數請求,它會正確返回。
var_dump
結果只是登錄信息。它沒有收到來自中間件的任何合併請求
On Laravel 5.2此代碼工作正常。任何解決方案?