会话闪存不起作用,放了[L5.2]

Pretty basic things going on. Using Session Flash messages to display any success/error messages.

All routes are set-up in my 'middleware' => 'web' group.

Now my problem. ->flash() does not work whilst ->put() does.

Controller:

$request->session()->flash('alert-success', 'My flash message');

Blade:

@foreach (['danger', 'warning', 'success', 'info'] as $msg)
    @if(Session::has('alert-' . $msg))
        <p class="alert alert-{{ $msg }}">{{ Session::get('alert-' . $msg) }} <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        </p>
    @endif
@endforeach

The return redirect('routeHere')->with('alert-success', 'My flash message'); stated in the Laravel 5 docs doesn't work either.

Edit

Laravel 5.2 Session flash not working even with web middleware duplication. Using ['middlewareGroups' => 'web'] instead of ['middleware' => 'web'] does fix the problem but assuming this is not the way to go.

After searching around out of curiosity for this problem i noticed an interesting update for laravel version >= 5.2.27 that applies by default the web middleware group to all the routes defined in routes.php.

Now this leads me to think that by declaring the middleware ['middleware' => 'web'] will lead to the code getting called twice, thus clearing the non-persistent flash messages.

A solution based on my assumption would be to simply not use:

Route::group(['middleware' => 'web'], function () {
});

This is where i found the update information :) Laravel 5.2 Auth not Working

Try to remove "web" middleware in the laravel 5.2 from your routes.php file. This way helps me