FilamentF
Filamentβ€’2y ago
Avriant

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 (exceeds the limit so I'll just drop the link here):
        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;
    }


I also tried
->afterValidation(function () {
                    $data = $this->form->getState();
                    $company = Company::create($data);
                    $company->users()->attach(auth()->user());
                    return $company;

Or (GPT)
            Wizard::make([
                Step::make('STEP 1')
                ->afterValidation(function () {
                    $company = Company::create([
                        'name' => $get('name'),
                        'slug' => $get('slug'),
                    ]);
                    $company->users()->attach(auth()->user());
Was this page helpful?