Try pulling in session via:
use Illuminate\Support\Facades\Session;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
My bet is that they arent in the web middleware group :) That means they dont have session.
https://laravelpackage.com/09-routing.html#configurable-route-prefix-and-middleware
Example in the telescope package: https://github.com/laravel/telescope/blob/4.x/config/telescope.php#L78
Please or to participate in this conversation.