[英]Redirecting with a message not working in Laravel 5
我的posts.create
操作中有以下代碼。
// ...
return redirect(route('posts.index'))->with('flashMessage', 'test');
// ...
我希望$flashMessage
變量在posts.index
視圖中可用,但是事實並非如此。 我究竟做錯了什么?
PS
我不想使用Session::flash('flashMessage', 'test')
設置Flash消息,因為在json響應的情況下它將不起作用。
在重定向中,您必須傳遞url而不是路由名稱將以下代碼添加到刀片頁面
@if(Session::has('flashMessage'))
<div class="alert alert-danger">
{{ Session::get('flashMessage') }}
</div>
@endif
似乎您的語法錯誤。 試試這個
return redirect()->route('posts.index')->with('flashMessage', 'test');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.