Skip to content

Commit

Permalink
Update Register.php
Browse files Browse the repository at this point in the history
Updated the registration to handle relation data if user customize the form, also added the default hooks for is a user wants to manipulate the data it is possible to do so.
  • Loading branch information
sitenzo committed Mar 31, 2024
1 parent fef8e7c commit 35edbd2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/panels/src/Pages/Auth/Register.php
Expand Up @@ -53,7 +53,11 @@ public function mount(): void
redirect()->intended(Filament::getUrl());
}

$this->callHook('beforeFill');

$this->form->fill();

$this->callHook('afterFill');
}

public function register(): ?RegistrationResponse
Expand All @@ -77,9 +81,23 @@ public function register(): ?RegistrationResponse
}

$user = $this->wrapInDatabaseTransaction(function () {
$this->callHook('beforeValidate');

$data = $this->form->getState();

return $this->handleRegistration($data);
$this->callHook('afterValidate');

$data = $this->mutateFormDataBeforeCreate($data);

$this->callHook('beforeCreate');

$this->record = $this->handleRegistration($data);

$this->form->model($this->record)->saveRelationships();

$this->callHook('afterCreate');

return $this->record;
});

event(new Registered($user));
Expand Down Expand Up @@ -243,4 +261,13 @@ protected function hasFullWidthFormActions(): bool
{
return true;
}

/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
protected function mutateFormDataBeforeCreate(array $data): array
{
return $data;
}
}

0 comments on commit 35edbd2

Please sign in to comment.