偶尔有TokenMismatchExceptions我遇到了问题所以我决定添加
if($e instanceof TokenMismatchException)
{
return \Redirect::to('auth/login')->withErrors(['Seems like you may have waited to long to use this application. Please refresh and try again.']);
}
到render
函数中的app / Exceptions / Handler.php文件。
我尝试了多种不同的重定向方式,视图从不显示错误。如果我的登录信息不正确,视图将显示错误。
如果我终止脚本并转储会话,我可以看到错误,但如果我在视图中转储会话,则错误对象为空。
查看
@if (isset($errors) && count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
路线
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
/**
* Need to be logged in to access all of these routes.
*/
Route::group(['middleware' => 'auth'], function(){
Route::get('/', function () {
return Redirect::to('/home');
});
});
Laravel 5.1
答案 0 :(得分:0)
试试这个:
return redirect('auth/login')->with('errors', ['Seems like you may have waited to long to use this application. Please refresh and try again.']);
然后在你看来:
@if (session('errors'))
<div class="alert alert-danger">
<ul>
@foreach (session('errors') as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif