我正在使用 Laravel 注册的默认类。问题:当我提交表单时,我知道有错误,因为用户没有添加到数据库中。但是当我使用
{{dd($errors)}}
结果是
ViewErrorBag {#226 ▼
#bags: []
}
我的验证规则是
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
和注册表
<form method="POST" action="{{ route('register') }}" class="form-signin">
@csrf
<img src="img/branding.svg">
<h2 class="form-signin-heading">{{__('Registreer')}}</h2>
<label for="email" class="sr-only">E-mailadres</label>
<input type="email" id="email" name="email" class="form-control" placeholder="E-mailadres" required autofocus>
<label for="name" class="sr-only">Gebruikersnaam</label>
<input type="text" id="name" name="name" class="form-control" placeholder="Gebruikersnaam" required>
<label for="password" class="sr-only">Wachtwoord</label>
<input type="password" id="password" name="password" class="form-control" placeholder="Wachtwoord" required>
<label for="password_confirmation" class="sr-only">Wachtwoord</label>
<input type="password" id="password_confirmation" name="password_confirmation" class="form-control" placeholder="Wachtwoord (herhaal)" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">{{ __('Registreren') }}</button>
{{dd($errors)}}
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
@if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</form>
一切看起来都很好,但我不知道为什么 Laravel 没有列出错误