我試圖在Laravel提交表單時顯示成功消息。Session :: flash在Laravel 5.2.27版本中不起作用
但是,它不起作用。
我在控制器文件的頂部添加了use Session;
,路由在中間件中,config/session.php中的配置是默認配置。
我的控制器功能能夠在數據庫中保存沒有任何問題:
public function store(Request $request)
{
$post = new Post;
$post->title = $request->title;
$post->description = $request->description;
$post->slug = $request->slug;
$post->body = $request->body;
$post->save();
Session::flash('success', 'SUCCESS MESSAGE GOES HERE');
return redirect()->route('posts.show', $post->id);
}
這裏是我的模板文件:
@if(Session::has('success'))
<div class="alert-box success">
<h2>{{ Session::get('success') }}</h2>
</div>
@endif
我的路線:
Route::group(['middleware' => ['web']], function() {
Route::get('/', '[email protected]');
Route::resource('posts','PostController');
});
是看會話文件沒有成功。我不明白爲什麼:
a:4:{s:6:"_token";s:40:"EntXIr9tkqAcKarDZhaNxKb6RfcFdFV9ZtF6W7kU";s:9:"_previous";a:1:{s:3:"url";s:30:"http://localhost:8000/posts/35";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:9:"_sf2_meta";a:3:{s:1:"u";i:1459467699;s:1:"c";i:1459467699;s:1:"l";s:1:"0";}}
有人可以幫助我找出問題是什麼?
Laravel 5.1或5.2? –
Laravel版本5.2.27 –
是否爲全新安裝?你的routes.php文件是什麼? – scrubmx