简体   繁体   中英

Laravel 5.3 Auth sessions not saving

While building my Laravel app I came across an issue: when I tried to login using Laravel's default auth scaffolding it did not work.
After some research I found out that it had something to do with sessions.
However something like this works fine:

Route::get('setsession', function () {
    Session::set('test', 'test');
});
Route::get('getsession', function () {
    dump(Session::get('test'));
});

I also tried this using a fresh installation of Laravel but with no luck either, so I really don't know what to do.

Kind regards,

Bart de Lange

The answer proved to be quite simple.

I forgot to update the $primaryKey variable in the user model to user_id.
In other words laravel tried to bind my users id (column 'id' in the users table which doesn't exist) in the session but failed and so the session value was null.
Which resulted in an Auth::check call that returned false.

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM