我在 Laravel 中有登录表单,它使用电子邮件和密码登录网站。我已经进行了所有验证,除了密码之外一切正常。当我输入错误的密码时,它会进入空白页,我想在密码字段下写一些错误。我查看了相同的内容:密码验证,但它不起作用。任何帮助表示赞赏。这是我的代码。
登录控制器.php
public function login(Request $request)
{
$rules = [
'email' => 'required|email|exists:App\User,email',
'password' => 'required|alphaNum|min:5'
];
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
$request->session()->put('data', $request->input());
return redirect()->route('login')
->withErrors($validator->errors())
->withInput($request->session()->put('data', $request->input()));
} else {
$userData = array(
'email' => $request->get('email'),
'password' => $request->get('password')
);
}
if (Auth::attempt($userData)) {
return redirect()->route('dashboard');
} else {
redirect()->route('login');
}
}
登录.blade.php
<div class="login-page">
<div class="login-box">
<div class="card mb-0">
<div class="card-body login-card-body">
<p class="login-box-msg font-weight-bold">Sign in to start your session</p>
<form method="POST" class="mb-4" action="{{route('login') }}">
@csrf
<div class="input-group mb-3">
<input id="email" type="email" placeholder="Email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
蓝山帝景