laravellaravel-5.8laravel-session

What is the purpose of creating table for Laravel Session?


I am confused why it is prerequisite of creating a database table for session based on the documentation, when session can work without it (db table).

Someone could explain me,

  1. I can directly session(['key' => 'value']); without the table, why we need to create a database table for session (based on documentation)?
  2. There is a thing called Redis. what is the purpose? and how to I use (I already installed)?

  3. What are the purpose of the fields like user_id, ip_address, user_agent, payload, last_activity? and how can these be useful?


Solution

  • The database and redis are just drivers to be used for storing session. By default laravel uses file driver which means you can still use session(['key' => 'value']); and that will be stored in file.

    If you chose to use the database then you will need to create the tables which Laravel then uses to store those value in.

    Redis is also a completely separate driver, and here is the wiki for it:

    Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability.

    So in conclusion you should chose which driver to use for your needs.