0
我偶尔TokenMismatchExceptions的问题,所以我决定向Laravel 5.1重定向withErrors()空鉴于
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.']);
}
添加到应用程序/例外/ Handler.php文件中render
功能。
我尝试了许多不同的方式来重定向,并且视图从不显示错误。如果我有不正确的登录信息,视图将显示错误。
如果我杀死了脚本并转储了会话,我可以看到这些错误,但是如果我在视图中转储会话,那么errors对象是空的。
查看
@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\[email protected]');
Route::post('auth/login', 'Auth\[email protected]');
Route::get('auth/logout', 'Auth\[email protected]');
/**
* 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
将'{{$ error}}'更改为'{!! $ error !!}' – aldrin27
我把这个变量放在视图中,它是空的 – Ethan22
这是在你的视图var_dump($ errors)'? – aldrin27