Friday, 13 August 2021

Laravel session driver file or database


 Laravel Session Driver database

To use the session driver database we need to make the following changes.

Updated .env file as follows:


SESSION_DRIVER=database


Make sure session_driver is set  config/session.php

'driver' => env('SESSION_DRIVER', 'database'),


Now run the command and create a session migration  


php artisan session:table


The above command will create a migration of the session table.

 To create a session table we need to run the laravel artisan command. 


php artisan migrate


You will see the session table structure something


create table sessions

(

  id varchar(255) not null,

  user_id int(10) unsigned null,

  ip_address varchar(45) null,

  user_agent text null,

  payload text not null,

  last_activity int not null,

  constraint sessions_id_unique

  unique (id)

);

If all goes well then laravel sessions will be stored in the database session table. 


Laravel Session Driver File


We need to update the session drive in .env to file 

SESSION_DRIVER=file


That is all we need to do if we want to use the file as a session driver file. 



No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...