Laravel 5.6 database sessions not working

Viewed 880

My app has been working with file-based sessions just fine. However, after switching to the database driver my sessions stopped working. This is exactly what happens:

  1. The user opens the login page (a session gets created in the sessions table with user_id = NULL)

  2. The user fills in his\her login credentials and submits the form (the session in the database acquires a user_id = 1)

  3. The system tries to redirect the user to a post-login page, however by that time the session has been terminated (the session has user_id = NULL)

To switch to the database driver I only did the following (the app was already working with file-based sessions):

Created the sessions table using:

  • php artisan session:table
  • composer dump-autoload
  • php artisan migrate

Configured config/sessions.php as follows:

  • 'driver' => env('SESSION_DRIVER', 'database')
  • 'connection' => 'mysql'
  • 'table' => 'sessions'
  • 'domain' => 'test.local'

My .env file:

  • DB_CONNECTION=mysql
  • SESSION_DRIVER=database

routes.php

Route::group(['domain' => 'test.local', 'middleware' => 'web'], function() {
    Route::group(['domain' => 'test.local', 'middleware' => 'auth'], function() {
        // post-login routes...
    }

    // show the login form
    Route::get('/login', 'Auth\LoginController@showLogin');

    // submit the login form
    Route::post('/login', 'Auth\LoginController@submitLogin');
}

Am I missing something? Any help is much appreciated.

0 Answers
Related