Custom registration and email verification

I want to add the phone of the user as a field inside the original registration form. I tried using a custom registration form and it worked but i dont know how to send the verification email during registration. When the user registers, he/she is redirected to the verification prompt (as i want) but the email is never delivered. If i click the "resend email" it works like charm. What gives?
return $panel
...
->registration(Register::class)
->emailVerification()
return $panel
...
->registration(Register::class)
->emailVerification()
class Register extends FilamentRegister
{
public function register(): ?RegistrationResponse
{
return DB::transaction(function () {
$data = $this->form->getState();

// Create the User and associate with the Group
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'], // Include the phone field
'password' => bcrypt($data['password'])
]);

// we need to somehow send the email here<-------

// Log the user in
auth()->login($user);

// Return the registration response
return app(RegistrationResponse::class);
});
}

protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPhoneFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data'),
),
];
}

protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')->required()->tel();
}
}
class Register extends FilamentRegister
{
public function register(): ?RegistrationResponse
{
return DB::transaction(function () {
$data = $this->form->getState();

// Create the User and associate with the Group
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'], // Include the phone field
'password' => bcrypt($data['password'])
]);

// we need to somehow send the email here<-------

// Log the user in
auth()->login($user);

// Return the registration response
return app(RegistrationResponse::class);
});
}

protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPhoneFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data'),
),
];
}

protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')->required()->tel();
}
}
Solution:
The reason is because you override the same register function . I think based practice is remove that function and replace with code below protected function handleRegistration(array $data): Model { ...
Jump to solution
2 Replies
Solution
Expecto Patronum
The reason is because you override the same register function . I think based practice is remove that function and replace with code below protected function handleRegistration(array $data): Model { $user = $this->getUserModel()::create($data);
return $user; } This one work for me
Christos
ChristosOP3w ago
Hey @Expecto Patronum thank you so much for this! This fixes the issue and everything works as expected!

Did you find this page helpful?