Search code examples
phpsessionlaravel-5.3

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


Solution

  • 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.