我试图重定向到上一页的消息时,有一个致命的错误。
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')
但是什么都没有渲染,是我做错了吗?
当前回答
拉拉维尔 8
Route::post('/user/profile', function () {
// Update the user's profile...
return redirect('/dashboard')->with('status', 'Profile updated!');
});
叶片的语法
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
在这里输入链接描述
其他回答
在叶片
@if(Session::has('success'))
<div class="alert alert-success" id="alert">
<strong>Success:</strong> {{Session::get('success')}}
</div>
@elseif(session('error'))
<div class="alert alert-danger" id="alert">
<strong>Error:</strong>{{Session::get('error')}}
</div>
@endif
在控制器 成功的
return redirect()->route('homee')->with('success','Successfully Log in ');
为错误
return back()->with('error',"You are not able to access");
Try
return Redirect::back()->withErrors(['msg' => 'The Message']);
在视图中调用这个
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@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
当我试图重定向时,我收到了这条消息:
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();
你有一个错误(拼写错误):
Sessions::get('msg')// an extra 's' on end
应该是:
Session::get('msg')
我想,现在应该有用了,对我来说确实有用。