我试图重定向到上一页的消息时,有一个致命的错误。
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')
但是什么都没有渲染,是我做错了吗?
当前回答
在控制器
例如
return redirect('login')->with('message',$message);
刀片锉 消息将存储在会话中而不是变量中。
例如
@if(session('message'))
{{ session('message') }}
@endif
其他回答
它适用于我和Laravel版本是^7.0
在控制器
return back()->with('success', 'Succesfully Added');
关于Blade文件
@if (session('success'))
<div class="alert alert-success">
{!! session('success') !!}
</div>
@endif
有关文档,请参阅Laravel文档
对于拉拉维尔3
只是提醒一下@giannis christofakis的回答;对于任何使用Laravel 3替代
return Redirect::back()->withErrors(['msg', 'The Message']);
:
return Redirect::back()->with_errors(['msg', 'The Message']);
**Try This**
Try This Code
--- Controller ---
return redirect('list')->with('message', 'Successfully');
return redirect('list');
---- Blade view ------
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
你有一个错误(拼写错误):
Sessions::get('msg')// an extra 's' on end
应该是:
Session::get('msg')
我想,现在应该有用了,对我来说确实有用。
当我试图重定向时,我收到了这条消息:
public function validateLogin(LoginRequest $request){
//
return redirect()->route('sesion.iniciar')
->withErrors($request)
->withInput();
当正确的方式是:
public function validateLogin(LoginRequest $request){
//
return redirect()->route('sesion.iniciar')
->withErrors($request->messages())
->withInput();