我在Laravel上遇到特定路由問題。每當有病人撥打特定的路線時,第二次(有時在第一次),生病會得到401認證中間件返回的錯誤。Laravel丟失會話(身份驗證)
文件中間件/ Authenticate.php
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401); // THIS IS CALLED
} else {
return redirect()->guest('login');
}
}
return $next($request);
}
從這個路線:
Route::group(['middleware' => 'auth'], function() {
.........
Route::get('events', '[email protected]');
});
TaskController.php
public function events(Request $request) {
$time_from = $request->start;
$time_to = $request->end;
$events = array();
$user_id = Auth::user()->id;
.....
return response()->json($events, 200);
}
所有的一個jQuery $不用彷徨請求調用。我不知道爲什麼Laravel認爲我是一個客人,然後失去了會議?
運行此命令:'php artisan route:list'並檢查特定路由是否通過了處理會話的Web中間件。 –