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

shankarnewton's avatar

Laravel Session not getting set

Issue Background

I'm trying to set session in my laravel 7.x but for some reason that's not working! I'm trying to reproduce the issue below to get some help.

  1. I've set my SESSION_DRIVER=database in .env file
  2. The\Illuminate\Session\Middleware\StartSession::class, line is also added under the middleware in kernal.php
  3. The config\session.php also has 'driver' => env('SESSION_DRIVER', 'database'), updated.
  4. Am setting up the session with the snippet session(['redirectUrl' => '/login']);

Now with the above configurations being set, when I try to set a session in controller, am expecting an entry in the database under the session table, however the session table is still empty! Can someone please advise if am missing out something?

PS: I've tried refreshing cache php artisan config:cache multiple times

0 likes
1 reply
shankarnewton's avatar
shankarnewton
OP
Best Answer
Level 1

Found it out! I'd been using dd() in my code snippet to see if my session was working. It turns out that using dd() restricts the complete execution of the middleware, hence my session was never set!

My Old Code:

Session::put('redirectUrl', 'value');
dd(Session::get('redirectUrl'); <---------- This didn't allow the session to be set in the first place.

So, in order to see if a session is working or not, comment out the dd() in the code snippet and let the execution to complete first.

Please or to participate in this conversation.