Laravel 返回视图显示消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38322590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel return view show message
提问by utdev
How can I show a message after I return a view in my Controller.
在我的控制器中返回视图后如何显示消息。
I am using Laravel 5.1.
我正在使用 Laravel 5.1。
return view('pr.new', [
'errorMessageDuration' => 'error too long',
'route' => 'createPr',
'type' => 'new',
]);
I tried to call the message like this:
我试图这样调用消息:
@if(session('errorMessageDuration'))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ session('errorMessageDuration') }}
{{ Input::get('title') }}
</div>
@endif
But it did not work, any ideas?
但它没有用,有什么想法吗?
回答by Rakesh Kumar
Use code Like This
像这样使用代码
@if(isset($errorMessageDuration))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ $errorMessageDuration }}
{{ Input::get('title') }}
</div>
@endif
回答by geckob
If you are using Redirect
, then you need to use session like what you did,
如果你正在使用Redirect
,那么你需要像你所做的那样使用 session,
Controller:
控制器:
return redirect('dashboard')->with('errorMessageDuration', 'Error!');
View:
查看:
@if(empty(session('errorMessageDuration')))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ session('errorMessageDuration') }}
{{ Input::get('title') }}
</div>
@endif
But if you pass the variables using View
facade, then you should just like what Rakesh showed:
但是如果你使用View
Facade传递变量,那么你应该就像 Rakesh 展示的那样:
Controller:
控制器:
return view('pr.new', [
'errorMessageDuration' => 'error too long',
'route' => 'createPr',
'type' => 'new',
]);
View:
查看:
@if(isset($errorMessageDuration))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ $errorMessageDuration }}
{{ Input::get('title') }}
</div>
@endif