Store sessions in the database

File sessions break when two servers handle the next request. database sessions follow the user.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-database-sessions-vue.md
File sessions break when two servers handle the next request. database sessions follow the user.
Do not use the file driver on a platform that runs more than one machine, or that does not keep local disk.
Do not put session rows in the same backup story as "we can delete the sessions table to clean up" without knowing you will log everyone out.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel database session Vue” stay on the file driver and then login sticks on one server and 419s on the other. The cookie is fine. The session file is on the other disk. The Sanctum guide is the cookie. This page is the driver.

TL;DR

  • File sessions break when two servers handle the next request.
  • database sessions follow the user.
  • Do not use the file driver on a platform that runs more than one machine, or that does not keep local disk.
  • Do not put session rows in the same backup story as “we can delete the sessions table to clean up” without knowing you will log everyone out.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

shell
php artisan session:table
php artisan migrate
ini
SESSION_DRIVER=database

Inertia visits then read the session from the database, including the CSRF token and the logged-in user. One database, many app servers.

What to avoid#

Gotcha

Do not use the file driver on a platform that runs more than one machine, or that does not keep local disk. Do not put session rows in the same backup story as “we can delete the sessions table to clean up” without knowing you will log everyone out. That part is fine on purpose. Doing it in the middle of the day is the outage.

FAQ#

How do I store sessions in the database?

File sessions break when two servers handle the next request. database sessions follow the user.

What goes wrong with Laravel database session Vue?

Many developers stay on the file driver and then login sticks on one server and 419s on the other. Do not use the file driver on a platform that runs more than one machine, or that does not keep local disk.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.