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

rahul95's avatar
Level 15

Having Problem with the Session Middleware classes

Hi, I have a webhook URL in my app, to which the Payment Gateway i am using will post the status of a transaction. A POST array to be clear. On this call back method i wanna catch a session variable i am setting prior to sending the user to the Bank's Payment form for further Payment related proceedings. Since the request is posted by another server on to the webhook URL, i have disabled the CSRF Protection for this route.

I have faced a problem here, that i can't access the Session variable i set earlier, which i need in order to identify the user who initiated the transaction, since i think Laravel is looking at the request object for Session variables. Anyway i have found a work around for this after a bit of googling, i have moved both \Illuminate\Session\Middleware\StartSession::class and \Illuminate\View\Middleware\ShareErrorsFromSession::class from the non-global middleware group to the Global middleware stack in the Kernal.php file. Now i'm getting the session variable there. But all of a sudden, on other parts of the app, the Validation error messages are gone missing. I have digged in to it and found out that, it is because i have moved those two middleware classes. When i put those back to where they originally were, Validation errors seems to be working.

Do you guys think, there is anyway to tackle both these situations.

I have to find a way to tackle the first case, to catch a session variable inside the webhook URL coming from another source. I have tried defining a custom middleware group with those two middleware classes and passed the route through that middleware but found no luck at all.

'custom_webhook' => [
        \Illuminate\Session\Middleware\StartSession::class,
         \Illuminate\View\Middleware\ShareErrorsFromSession::class,
]
0 likes
0 replies

Please or to participate in this conversation.