很基本的事情正在进行。使用Session Flash
消息显示任何成功/错误消息。会话flash不能正常工作,放入[L5.2]
所有路线都在我的'middleware' => 'web'
组中设置。
现在我的问题。 ->flash()
不起作用,而->put()
。
控制器:
$request->session()->flash('alert-success', 'My flash message');
刀片:
@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">×</a>
</p>
@endif
@endforeach
在Laravel 5 docs陈述的return redirect('routeHere')->with('alert-success', 'My flash message');
也不起作用。
编辑
Laravel 5.2 Session flash not working even with web middleware重复。使用['middlewareGroups' => 'web']
而不是['middleware' => 'web']
确实解决了这个问题,但假设这不是要走的路。
您确定要在最近的下一个请求中使用它。因为'flash'只适用于下一个请求......并且如果你想在稍后的任何请求中获得这个消息,你应该使用'put'。 –
是的,我想要那个。同样的问题在这里:http://stackoverflow.com/questions/36279871/laravel-5-2-session-flash-not-working-even-with-web-middleware?rq=1(使用'middlewareGroups'而不是'中间件'可以工作,但不是我想的方式。 – Liam
你可以在视图中转储:'{{dd($ request-> session() - > all())}}' –