我试图重定向到上一页的消息时,有一个致命的错误。
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::back()->withInput()->withErrors(array('user_name' => $message));
View
<div>{{{ $errors->first('user_name') }}}</div>
其他回答
拉拉维尔 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
在这里输入链接描述
在Laravel 5.5中:
return back()->withErrors($arrayWithErrors);
在使用Blade的视图中:
@if($errors->has())
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
我也遇到过同样的问题,这个方法奏效了。
控制器
return Redirect::back()->withInput()->withErrors(array('user_name' => $message));
View
<div>{{{ $errors->first('user_name') }}}</div>
对于拉拉维尔3
只是提醒一下@giannis christofakis的回答;对于任何使用Laravel 3替代
return Redirect::back()->withErrors(['msg', 'The Message']);
:
return Redirect::back()->with_errors(['msg', 'The Message']);
在叶片
@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");