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 ...
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 Sorry, I don't understand well, but yes works without web middleware ...
// route
Route::group(['middleware' => 'web'], function () {
Route::resource('posts', 'PostController');
});
// Change to this, remove the web middleware
Route::resource('posts', 'PostController');
Please or to participate in this conversation.