Filament Wizard Save to Different Tables on each Step
I suck at this, so any help would be much appreciated :)
Want: Wizard that on each step stores information in different tables
Have: Multitenant Filament V3 Form. RegisterTenant needs to be a Wizard. Schema looks like this:
return $form->schema([
Wizard::make([
Step::make('STEP 1')
->schema([
TextInput::make('name')
TextInput::make('slug')
]),
Step::make('STEP 2')
->schema([
Fieldset::make('Profile Information')
->relationship('general')
->schema([
TextInput::make('name_madoguchi')
TextInput::make('phone')
TextInput::make('email_madoguchi')
]),
])
])
->persistStepInQueryString()
->startOnStep(1),
]);
protected function handleRegistration(array $data): Company
{
$data = $this->form->getState();
$company = Company::create($data);
$company->users()->attach(auth()->user());
session(['active_tenant_id' => $company->id]);
$this->form->model($company)->saveRelationships();
return $company;
}
Tried:
Pattern One:
Wizard::make([
Step::make('STEP 1')
->afterValidation(function () {
$company = Company::create([
'name' => $get('name'),
'slug' => $get('slug'),
]);
$company->users()->attach(auth()->user());
Does not work, $get does not exist error (solution proposed by AI)
Pattern Two:
->afterValidation(function () {
$data = $this->form->getState();
$company = Company::create($data);
$company->users()->attach(auth()->user());
return $company;
Simply does not work, focuses on the window and does not even move to the next step of the Wizard
Pattern Three:
protected function handleRegistration(array $data): Company
{
$data = $this->form->getState();
$company = Company::create($data);
// relationship function name in Company.php
$company->users()->attach(auth()->user());
session(['active_tenant_id' => $company->id]);
$this->form->model($company)->saveRelationships();
return $company;
}
Saves only to 1 table, the fields for the second table are not fetched :(
Also bonus points if someone can tell me how to ->relationship directly on a Wizard without having to wrap the whole thing in FieldSet or Section, because this does not look good.
Please or to participate in this conversation.