Auth::user() returns null in Laravel 5.2

前端 未结 4 779

I have searched and found various results like these: auth()->user() is null in Laravel 5.2 and Auth::user() returns null

But, mine is still not working.

4条回答
  •  北海茫月
    2021-01-06 10:30

    From the same discussion that the accepted answer links to, I found the following solution to work. Edit your /routes/web.php file and surround your existing routes with Route::group('middleware' => 'web']), like so:

    Route::group(['middleware' => 'web'], function () {
    
        Auth::routes();
    
        // The rest of your routes
    
    });
    

    As far as I understand, this will not have any security or other implications, as it is simply loading the web middleware prior to processing the contained routes. If anyone knows of security or other concerns / ramifications, please post them in the comments on this answer.

提交回复
热议问题