如何解决laravel中间件未在刀片中获得错误代码或会话消息
有一个页面,我在其中提交ID,然后中间件检查是否正确,然后重定向到另一条路线。中间件工作正常,但是我无法在刀片中获得消息。
中间件:
public function handle($request,Closure $next)
{
$exists =Kuponas::where('id',$request->id)->exists();
if (!$exists) {
return \Redirect::to(url('/'))->with('pin','Duomenys neteisingi,patikrinkite ');
}
return $next($request);
}
刀片:
@error('pin')
<p>
<i><b>Error:</b> {{ $message }}</i>
</p>
@enderror
或
@if ($message = Session::get('pin'))
<div class="alert alert-success alert-block"
style="position:relative;left:260px;width: 50%;text-align: center;">
<button type="button" style="position:relative; bottom: 5px; color: white;" s="close"
data-dismiss="alert">×</button>
<strong style="color: white;">{{ $message }}</strong>
</div>
@endif
如果我在输入中输入了错误的值,则也不起作用。
解决方法
尝试一下,刀片:
@if(session('pin'))
<p>
<i><b>Error:</b> {{ $message }}</i>
</p>
@endif
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。