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

FrogMen's avatar
Level 14

Laravel 11 session handling problems

I have two repos , one is the caller (Laravel 11) and other is the auth repo (Laravel 10). In theory I send a post request from the caller to the auth api, it authenticates my valid user, logs in, and redirects back to the caller project. The two projects has the same session cookie settings, they are on same domain, etc.

The problem is, even I have valid credentials the auth don't persist the user in session after redirect. We use custom session driver, but between L10-L10 projects this communication works!

After lot of searching I found same solution from diff. sources, thats the following, append StartSession middleware in the app.php:

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(StartSession::class); // <- this line
        $middleware->web(append: [PortfolioUserSessionHandler::class]);

with this trick I have the logged in user in the caller project after redirect, but as a commenter said, this solution force session regenerate on every request, what is true, and not good.

If I add the StartSession::class to the web middleware, where originally exists, then again not works.

Any idea what should be the problem, the two Laravel versions use the session in different way, or.. ?

(source: https://dev.to/abdulwahidkahar/how-to-fix-session-store-not-set-on-request-laravel-11-2d4p)

1 like
4 replies
vincent15000's avatar

Is the session stored in a cookie ? in the database ? in a file ?

FrogMen's avatar
Level 14

the session is stored in a memcached instance

Meantime I realised that adding the line "StartSession" in the app.php "reset" the session, the error message bag is always empty. Removing this line message bag works again. Hm...

1 like
vincent15000's avatar

@FrogMen I don't know this line StartSession in the app.php configuration file.

Can you give me an example ?

FrogMen's avatar
Level 14

in the blog post I linked the solution was to add StartSession middleware in the bootstrap/app.php and not config/app.php.
and you can see in the code example part what I inserted.

search for StartSession in the framework what it does exactly.

1 like

Please or to participate in this conversation.