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

vandyczech's avatar

Laravel 5.2.39 - Session flash not working

Hi, I have Laravel 5.2.39 and I try use status session message like this:

// Kernel
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, ];

protected $middlewareGroups = [ 'web' => [

                \app\Http\Middleware\EncryptCookies::class,
                \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
                \Illuminate\Session\Middleware\StartSession::class,
                \Illuminate\View\Middleware\ShareErrorsFromSession::class,
                \app\Http\Middleware\VerifyCsrfToken::class,
],

// route
Route::group(['middleware' => 'web'], function () {
        Route::resource('posts', 'PostController');
});

// controller
return redirect()->route('posts.create')->with('status', 'Profile updated!');

// blade
@if (session('status'))
{{ session('status') }}
@endif

But it seems, that session not working well ...

0 likes
4 replies
SaeedPrez's avatar

99% of the time (percent taken out of my a$$) when the session flash is not working it's because there is second redirect involved.

But actually try without the web middleware in your route group, it should be applied automatically to all routes in later Laravel version.s

SaeedPrez's avatar
Level 50
// route
Route::group(['middleware' => 'web'], function () {
        Route::resource('posts', 'PostController');
});
// Change to this, remove the web middleware
Route::resource('posts', 'PostController');
1 like

Please or to participate in this conversation.