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

pstephan1187's avatar

Overridden StartSession Middleware not Persisting Session

I am trying to implement a custom StartSession Middleware. No matter what I try, it seems that anything other than the Illuminate StartSession Middleware will not persist the session. I have tried using a class that extends the Illuminate one and I have also tried copying the Illuminate one verbatim (updating the namespace of course). But no matter what I try, the session will not persist. I am using the File session driver. When I use the Illuminate middleware, a session file is created when a page is requested, but not on any custom middleware. Any ideas? Essentially I want to add an event to the session middleware.

0 likes
2 replies
pstephan1187's avatar
pstephan1187
OP
Best Answer
Level 7

Come to find out, the Session Service Provider registers the middleware, so I have to extend the service provider and register my own middleware for it to work.

Please or to participate in this conversation.