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

peterlee's avatar

purpose of using web middleware when saving session

Hi, I just solved the problem that not storing session value, like writing a single line code session( [ 'key' => 'value' ]); by set rouing as 'web' middleware Route::group([ 'middleware' => ['web'] ], function () { .... }

but I still do not understand why web middleware is required in order to save session key - value in framework/sessions

what's the purpose of using web middleware to store session value ?

0 likes
1 reply
tiagotavares's avatar
Level 15

Hey,

As you can see from the docs https://laravel.com/docs/5.4/middleware#middleware-groups , the web is a an alias for easier reference in the routes and \Illuminate\Session\Middleware\StartSession::class is part of it.

It contains some just some boilerplate so you don't need to worry about the basic initialisation for "normal" web requests each time.

You are free to change it for your needs.

Hope this helps!

1 like

Please or to participate in this conversation.