我试图重定向到上一页的消息时,有一个致命的错误。
App::fatal(function($exception)
{
return Redirect::back()->with('msg', 'The Message');
}
在视图中尝试访问msg
Sessions::get('msg')
但是什么都没有渲染,是我做错了吗?
我试图重定向到上一页的消息时,有一个致命的错误。
App::fatal(function($exception)
{
return Redirect::back()->with('msg', 'The Message');
}
在视图中尝试访问msg
Sessions::get('msg')
但是什么都没有渲染,是我做错了吗?
当前回答
对于拉拉维尔3
只是提醒一下@giannis christofakis的回答;对于任何使用Laravel 3替代
return Redirect::back()->withErrors(['msg', 'The Message']);
:
return Redirect::back()->with_errors(['msg', 'The Message']);
其他回答
在laravel 5.8中,你可以做以下事情:
return redirect()->back()->withErrors(['name' => 'The name is required']);
在刀刃上:
@error('name')
<p>{{ $message }}</p>
@enderror
Try
return Redirect::back()->withErrors(['msg' => 'The Message']);
在视图中调用这个
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
在控制器
例如
return redirect('login')->with('message',$message);
刀片锉 消息将存储在会话中而不是变量中。
例如
@if(session('message'))
{{ session('message') }}
@endif
另一种方法是
控制器
use Session;
Session::flash('message', "Special message goes here");
return Redirect::back();
View
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif
对于拉拉维尔3
只是提醒一下@giannis christofakis的回答;对于任何使用Laravel 3替代
return Redirect::back()->withErrors(['msg', 'The Message']);
:
return Redirect::back()->with_errors(['msg', 'The Message']);