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

shanely's avatar

how does laravel use the session in framework itself

can I ask in laravel core where does the session play in framework itself where does the session started, I didn't see the session_start in the core.

Thank you in advance.

0 likes
6 replies
Snapey's avatar

I think it's called in the web middleware

gator's avatar

When in doubt, always go to the source.. Here is the starting point :

  1. In App\Http\Kernel, Global middleware Illuminate\Session\Middleware\StartSession is called (this happens for EVERY REQUEST)

  2. The constructor (StartSession class) instantiates the appropriate \Illuminate\Session\SessionManager based on your config settings (defaults to file)

  3. Notice comments inside the handle method of the StartSession middleware:

// Note that the Laravel sessions
// do not make use of PHP "native" sessions in any way since they are crappy.

And so on..

Snapey's avatar

@gator

In App\Http\Kernel, Global middleware Illuminate\Session\Middleware\StartSession is called (this happens for EVERY REQUEST)

Correct me please if I am wrong. StartSession only occurs for web requests and not api requests

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];
gator's avatar

@Snapey, you are right. Web requests only. I missed the API group as I was looking at the source code of Laravel 5.0 :-)

Please or to participate in this conversation.