我在注册表上尝试了我的代码。 当我单击注册按钮时,会出现一些错误。 你能帮帮我解决这个问题吗? Register Form Screenshoot
迁移create_user_table
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
MenuItem m = menu.getItem(0);
m.setIcon(R.drawable.your_icon_here);
}
return true;
}
RegisterController.php
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');
}
然后在我的登记表上:
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);
}
答案 0 :(得分:0)
就个人而言,在Schema中我会创建'phone'字段->nullable()
,并添加->default(null)
。然后,您可以从RegisterController.php文件中删除'phone' => 'required'
验证。