loic.lopez
loic.lopez

Reputation: 2103

Laravel 5.4 database session not working

I have problems with the database driver for storing sessions :

Connection to database is currently working. Cookies are not set in the browser but are set in my database.

i have run :

php artisan session:table

My .env :

SESSION_DRIVER=database

config/session.php

'driver' => env('SESSION_DRIVER', 'file'),
'connection' => 'mysql',
'table' => 'sessions',

EDIT 1:

my route :

Route::group(['domain' => GetDomainInfo::GetDomainName(), 'middleware' => 'web'], function ()
{
  Route::get('/', "HomeController@index");
}

Thanks for help.

Upvotes: 2

Views: 7815

Answers (1)

Frondor
Frondor

Reputation: 3466

When you work with the database driver for sessions, you have to create the session table.

I'll assume you already scaffold the native authentication system by doing php artisan make:auth and migrated the migrations.

So first you generate the migration, and then migrate:

php artisan session:table

Execute the migration:

php artisan migrate

Obviously, this won't work if the routes you're checking on, aren't using the web middleware. If you're not registering the routes in /routes/web.php, then you have to manually specify the web middleware for them. Either in your controller's constructor, or directly in the route itself.

Also, check your domain in config/session.php is the same you're using in development or production, depending where you are working on.

Upvotes: 3

Related Questions