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

jeroenvanrensen's avatar

Laravel Package Session does not save

Hi everyone,

I'm creating a Laravel Package and I'm using sessions.

This is my routes/web.php file (in my package dir):

Route::get('/set', function () {
    Session::put('key', 'value');
});

Route::get('/get', function () {
    return Session::get('key', 'value');
});

If I browse to /set and next to /get it shows nothing (a blank page).

But this code does work:

Route::get('/get', function () {
    Session::put('key', 'value');
    return Session::get('key', 'value');
});

Note: I'm using the file driver, but with database it works neither.

Does anyone know what's happening here?

Thank you! Jeroen

0 likes
5 replies
jlrdw's avatar

Try pulling in session via:

use Illuminate\Support\Facades\Session;

jeroenvanrensen's avatar

@jlrdw Yes I did, this is my routes/web.php file (in my package folder):

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;

Route::get('/set', function () {
    Session::put('key', 'value');
});

Route::get('/get', function () {
    return Session::get('key');
});

Please or to participate in this conversation.