Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mahuresanketr's avatar

Laravel 5.4 routing issue with database based session

Previously we are using file based session and project is working fine. From last 2 days i am trying to change file based session to database session and below steps are followed: 1.Created session table CREATE TABLE sessions ( id int(11) NOT NULL, user_id int(11) DEFAULT NULL, ip_address varchar(45) DEFAULT NULL, user_agent text, payload text NOT NULL, last_activity int(11) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB;

  1. Then run below commands: php artisan session:table php artisan migrate

  2. In config/session.php file 'driver' => env('SESSION_DRIVER', 'database')

  3. In .env file SESSION_DRIVER=database

  4. Cleared config,cache and route php artisan config:clear php artisan route:clear php artisan cache:clear

But i am facing issue with routes, on form submit method is POST but still in Request getting as GET and in web.php Route::match(['get', 'post'],'/test', 'Quote@car');

I wanted to setup database session for the laravel 5.4 project

Please help me with this isssue.

0 likes
8 replies
jlrdw's avatar

Have you tried any instead of match. It's worked pretty well for me.

Snapey's avatar

I would also clear any cookies in your browser.

Does it behave the same if you use an in-private browser session?

Also, check your routes with php artisan route:list

mahuresanketr's avatar

Thank you but after changeing into table staructure as follows working partially:

Query: CREATE TABLE sessions ( id varchar(255) NOT NULL, user_id bigint(20) unsigned DEFAULT NULL, ip_address varchar(45) DEFAULT NULL, user_agent text, payload text NOT NULL, last_activity int(11) NOT NULL, UNIQUE KEY sessions_id_unique (id) ) ENGINE=InnoDB;

Now session is not avaiable in next controller. Sessions values are aviable into same controller and blade but not in next controller.

Snapey's avatar

Not sure why you are creating the table migration manually? The artisan command does it for you?

mahuresanketr's avatar

Artisan command created session table,we only changed collation.

mahuresanketr's avatar
mahuresanketr
OP
Best Answer
Level 1

Used Session::save(); to persist session and its working for me

Snapey's avatar

You only need to use save if you are not allowing the request cycle to terminate normally.

mahuresanketr's avatar

Can you please explain little in detail regarding request cycle termination?

Please or to participate in this conversation.