我使用Laravel的标准注册和登录。我根据自己的需要调整了这一点并扩展了一些领域。但总是我收到错误消息"密码字段是必需的"当我建立一个新用户。此错误消息来自何处?
web.php
// Registration Routes...
Route::get('index', 'Auth\RegisterController@showRegistrationForm');
Route::post('index', 'Auth\RegisterController@register');
index.blade.php
<div class="col-md-6 col-md-offset-1">
<div class="row pt-100">
<h2>xyz</h2>
<form class="nomargin sky-form" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<fieldset>
<div class="row">
<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
<div class="col-md-6 col-sm-6">
<label class="sr-only" for="name">name</label>
<label class="input margin-bottom-10">
<i class="ico-append fa fa-user"></i>
<input type="text" id="name" placeholder="Name" name="name" value="{{ old('name') }}" required autofocus>
<b class="tooltip tooltip-bottom-right">Dein Name</b>
</label>
</div>
</div>
<div class="form-group {{ $errors->has('username') ? ' has-error' : '' }}">
<div class="col-md-6 col-sm-6 mtm-15">
<label class="sr-only" for="username">username</label>
<label class="input margin-bottom-10">
<i class="ico-append fa fa-user"></i>
<input type="text" id="username" placeholder="Username" name="username" value="{{ old('username') }}" required autofocus>
<b class="tooltip tooltip-bottom-right">Dein Username</b>
</label>
</div>
</div>
</div>
<div class="row">
<div class="form-group {{ $errors->has('email') ? ' has-error' : '' }}">
<div class="col-md-12 col-sm-12 mtm-15">
<label class="sr-only" for="email">email</label>
<label class="input margin-bottom-10">
<i class="ico-append fa fa-envelope"></i>
<input type="email" id="email" placeholder="eMail" name="email" value="{{ old('email') }}" required autofocus>
<b class="tooltip tooltip-bottom-right">Deine eMail</b>
</label>
</div>
</div>
</div>
<div class="row">
<div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}">
<div class="col-md-12 col-sm-12 mtm-15">
<label class="sr-only" for="password">password</label>
<label class="input margin-bottom-10">
<i class="ico-append fa fa-lock"></i>
<input type="password" id="password" minlength="6" placeholder="Passwort" requiered>
<b class="tooltip tooltip-bottom-right">Min. 6 Zeichen lang</b>
</label>
</div>
</div>
</div>
<div class="row">
<div class="form-group {{ $errors->has('gender') ? ' has-error' : '' }}">
<div class="col-md-3 pt-3">
<label class="sr-only" for="male">male</label>
<label class="radio">
<input type="radio" name="gender" value="male" id="gender" requiered autofocus>
<i></i> <span style="color:white">Männlich</span>
</label>
</div>
<div class="col-md-3 pt-3">
<label class="sr-only" for="female">female</label>
<label class="radio">
<input type="radio" name="gender" value="female" id="gender" requiered autofocus>
<i></i> <span style="color:white">Weiblich</span>
</label>
</div>
</div>
<div class="form-group {{ $errors->has('birthday') ? ' has-error' : '' }}">
<div class="col-md-6 mtm-15">
<label class="sr-only" for="birthday">birthday</label>
<label class="input margin-bottom-10">
<input type="date" id="birthday" name="birthday" value="{{ old('date') }}" placeholder="Geburtsdatum" requiered autofocus>
<b class="tooltip tooltip-bottom-right">Dein Geburtsdatum</b>
</label>
</div>
</div>
</div>
<div class="row form-group {{ $errors->has('agb') ? ' has-error' : '' }}">
<div class="col-md-12 mt-20">
<label class="checkbox nomargin">
<input class="checked-agree" type="checkbox" id="agb" value="agree" required>
<i></i>
<span style="color:white">Hiermit bestätige ich die </span>
<a href="#" data-toggle="modal" data-target="#termsModal">AGB/Datenschutzerklärung</a>
</label>
</div>
</div>
</fieldset>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> REGISTRIEREN</button>
</div>
</div>
</div>
</form>
</div>
</div>
迁移
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username')->unique();
$table->string('email')->unique();
$table->text('biografie');
$table->string('password');
$table->string('gender');
$table->date('birthday');
$table->text('privacy');
$table->string('agb');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
user.php的
protected $fillable = [
'name', 'email', 'password', 'username', 'gender', 'birthday', 'agb'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
registercontroller
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:30',
'username' => 'required|string|max:20|unique:users',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'gender' => 'required|string',
'birthday' => 'required|date',
'agb' => 'required|string',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'gender' => $data['gender'],
'birthday' => $data['birthday'],
'agb' => $data['agb'],
]);
}
}
答案 0 :(得分:1)
您在输入字段中缺少名称属性。
只需更改输入字段。
<input type="password" id="password" minlength="6" name="password" placeholder="Password" requiered>
现在,您将收到无效确认密码的错误,因为您缺少password_confirmation输入字段。
在您的注册表单中包含密码确认字段。
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
你很高兴。