这是我的 login.blade.php
@if(Session::get('errors')||count( $errors ) > 0)
@foreach ($errors->all() as $error)
<h1>{{ $error }}</h1>
@endforeach
@endif
这是我的 LoginController.php:
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
$this->username() => 'ERRORS',
]);
}
这是我的 web.php(路由)
// I am customizing the login to do extra checks,
// but I still need the basic auth scaffolding.
Auth::routes();
...
Route::group(['middleware' => 'web'], function () {
Route::view('/login', 'auth.login');
Route::post('/login', 'Auth\LoginController@login')->name('login');
});
当我尝试使用不良用户登录时,它在 View 中没有显示任何错误,我做错了什么?
更新:
我试过按照@Seva Kalashnikov 的建议更改 login.blade.php,但没有成功。
我也尝试过@Akshay Kulkarni 的建议,但没有成功。
最佳答案
尝试从 login.blade.php 中的 if
语句中删除 Session::get('errors')
@if(count( $errors ) > 0)
@foreach ($errors->all() as $error)
<h1>{{ $error }}</h1>
@endforeach
@endif
ShareErrorsFromSession
中间件,由 web 中间件组提供,负责 $error
View 变量,因此它将始终被定义 ( link here )
[更新]
正如@Ohgodwhy 指出的那样,您需要使用@if ($errors->any())
Example
所以在你的情况下它将是:
@if($errors->any())
@foreach ($errors->all() as $error)
<h1>{{ $error }}</h1>
@endforeach
@endif
关于php - Laravel 5.5 登录错误未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47104941/