gpt4 book ai didi

php - Laravel 5.5 登录错误未显示

转载 作者:可可西里 更新时间:2023-11-01 13:59:30 25 4
gpt4 key购买 nike

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com