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

HUGE_DICK_10_INCHES's avatar

Setting or starting/stoping session in exception handler

I made some view for not found error but I cannot use auth()->user() inside view so I changed handler into redirecting to 404 route /404 where I display errors like:

https://www.website.com/something/something link is broken and from other pages where handler is not used I pass current url as session:

redirect()->route('404')->withStatus(['url'=>url()->current()]); And I use this:

@if($s = session('status'))
   {{$s['url']}} link is broken
@endif  

But from handler I cannot set session.

So I thought about fetching previous url but it fetches url before one followed by handler... So I am stuck with trying to pass url that is not found and handler handles it :D

Since its bad to start session in handler cuz of apis can I start/stop it just to set or should I use a cookie?

0 likes
0 replies

Please or to participate in this conversation.