© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
Anik

multiple models with relationships with Wizard Steps

Hi, I am using a Wizard Step with a model on a custom page to create and edit the model. I am having issues with SpatieMediaUpload which doesn't save the relation the first time on create but works well on edit. Sample code below
in Mount
$this->kyc = is_null($existKycRecord) ? $this->user->kyc()->getModel() : $existKycRecord;

Step::make('kyc')->model($this->kyc)
                 ->afterValidation(function (Closure $get) {
                        $kycForm = [
                            'type' => $get('user_type'),
                            'has_tax' => $get('has_tax'),
                        ];
                        $this->saveKyc($kycForm);
                    }),

Save function
   public function saveKyc($data)
    {
        $this->kyc = $this->kyc->updateOrCreate(['user_id' => $this->user->id], $data);

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

        $this->notify('success', 'User KYC Saved successfully!');
     
    }
in Mount
$this->kyc = is_null($existKycRecord) ? $this->user->kyc()->getModel() : $existKycRecord;

Step::make('kyc')->model($this->kyc)
                 ->afterValidation(function (Closure $get) {
                        $kycForm = [
                            'type' => $get('user_type'),
                            'has_tax' => $get('has_tax'),
                        ];
                        $this->saveKyc($kycForm);
                    }),

Save function
   public function saveKyc($data)
    {
        $this->kyc = $this->kyc->updateOrCreate(['user_id' => $this->user->id], $data);

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

        $this->notify('success', 'User KYC Saved successfully!');
     
    }

The form isn't saved when saveKyc is run the first time (on wizard next) but the function saves the relationships if it's run a second time (going previous and next on the wizard). I am looking for a way to save a multi model form with attachments via SpatieMedia.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Form Wizard multiple steps
FilamentFFilament / ❓┊help
2y ago
Form Wizard multiple models
FilamentFFilament / ❓┊help
2y ago
wizard with many steps
FilamentFFilament / ❓┊help
2y ago
same relationship on multiple wizard steps
FilamentFFilament / ❓┊help
2y ago