0
我已經在註冊表格上試過我的代碼。 當我點擊註冊按鈕時,出現一些錯誤。 你能幫我解決這個問題嗎? Register Form Screenshoot如何將我的附加字段連接到Laravel 5.4上的數據庫?
遷移create_user_table
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('phone');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'username' => 'sometimes|required|max:255|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
'phone' => 'required',
'terms' => 'required',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$fields = [
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'phone' => $data['phone'],
];
if (config('auth.providers.users.field','email') === 'username' && isset($data['username'])) {
$fields['username'] = $data['username'];
}
return User::create($fields);
}
然後我的登記表上:
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Phone Number" name="phone" value="{{ old('phone') }}"/>
<span class="glyphicon glyphicon-phone form-control-feedback"></span>
</div>
你可以發佈你的型號代碼嗎? – Samsquanch
你可以在'User :: create'之前做'dd($ fields)',並將輸出和模型代碼一起發佈嗎? – Paras