Level 1
Anybody have any ideas how I could change this to work with the StartSession middleware?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My middleware code:
public function handle(Request $request, Closure $next) {
if ($request->isMethod('get') && (!$request->hasSession() || $request->session()->pull('framed', false) == false)) {
return response()->view('dashboard.frame');
}
$response = $next($request);
if ($response instanceof RedirectResponse && $request->hasSession()) {
$request->getSession()->flash('framed', true);
}
return $response;
}
This works unless I have Illuminate\Session\Middleware\StartSession in my global middleware in my Kernel. The problem is that I need StartSession for other aspects of my site to work. Does anybody know why this would be happening?
I figured it out! The problem was that I had StartSession in both $middlewareGroups['web'] and $middleware.
Please or to participate in this conversation.