Php Can';t在Laravel中使用错误消息重定向
我试图在CPE mac不存在时抛出一条警报消息。 但我从未见过它Php Can';t在Laravel中使用错误消息重定向,php,laravel,laravel-5,laravel-5.1,Php,Laravel,Laravel 5,Laravel 5.1,我试图在CPE mac不存在时抛出一条警报消息。 但我从未见过它 if(!$cpe_mac){ return view('main.lan') ->with('error','There is no CPE associated with this account !'); } 第二次尝试 @if ($message = Session::get('success')) <div class="al
if(!$cpe_mac){
return view('main.lan')
->with('error','There is no CPE associated with this account !');
}
第二次尝试
@if ($message = Session::get('success'))
<div class="alert alert-sm alert-block alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<i class="fa fa-check green"></i>
<strong class="green">{{ nl2br($message) }}</strong>
</div>
@elseif ($message = Session::get('error'))
<div class="alert alert-sm alert-block alert-danger">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong class="red">{{ nl2br($message) }}</strong>
</div>
@endif
return Redirect::to('/lan')->带有('error','没有与此帐户关联的CPE!')代码>
页面被困在重新定向循环中,并显示此错误消息
alert.blade.php
@if ($message = Session::get('success'))
<div class="alert alert-sm alert-block alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<i class="fa fa-check green"></i>
<strong class="green">{{ nl2br($message) }}</strong>
</div>
@elseif ($message = Session::get('error'))
<div class="alert alert-sm alert-block alert-danger">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong class="red">{{ nl2br($message) }}</strong>
</div>
@endif
@if($message=Session::get('success'))
{{nl2br($message)}
@elseif($message=Session::get('error'))
{{nl2br($message)}
@恩迪夫
有什么线索吗?下面是交易:
@if ($message = Session::get('success'))
<div class="alert alert-sm alert-block alert-success">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<i class="fa fa-check green"></i>
<strong class="green">{{ nl2br($message) }}</strong>
</div>
@elseif ($message = Session::get('error'))
<div class="alert alert-sm alert-block alert-danger">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong class="red">{{ nl2br($message) }}</strong>
</div>
@endif
if(!$cpe_mac){
return view('main.lan')
->with('error','There is no CPE associated with this account !');
}
响应视图并向其附加一个错误变量,因此您的alert.blade.php应该如下所示:
//the error part
@elseif ($error)
<div class="alert alert-sm alert-block alert-danger">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong class="red">{{ nl2br($error) }}</strong>
</div>
@endif
在您的lan路由上,您一次又一次地重定向,但通过这种方法,变量将确实处于会话中,因为您正在重定向数据并将其存储为flash消息
综上所述:
return view('main.lan')
->with('error','There is no CPE associated with this account !');
创建变量$error并加载视图
关于这一点:
return Redirect::to('/lan')->with('error','There is no CPE associated with this account !');
在会话中存储数据并重定向到提供的路由,因此在下一个路由上,您可以使用会话外观或session()
helper()访问数据