Reputation:
I would like to add two fields to the table user. the first name and a key.
on RegisterController
protected function validator(array $data)
{
return Validator::make($data, [
'nom' => ['required', 'string', 'max:255'],
'prenom' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'cle' => ['required', 'string', 'unique:users'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
$rand = rand(9999, 999999999);
$cle = 'Pa'.$rand;
return User::create([
'nom' => $data['nom'],
'prenom' => $data['prenom'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'cle' => $cle,
]);
}
On user model
protected $fillable = [
'nom', 'prenom', 'email', 'password', 'cle',
];
table migration
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('nom');
$table->string('prenom');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('cle')->unique();
$table->rememberToken();
$table->timestamps();
});
}
I have no errors, but the registration does not go to the database and I stay on the registration page
Upvotes: 0
Views: 88
Reputation: 4271
Remove this line 'cle' => ['required', 'string', 'unique:users'],
from your validator()
method, as you're generating cle randomely in you create()
method, and you don't need to receive this parameter.
Maybe you have an invisible error for this field.
Upvotes: 1