F
Filamentβ€’2y ago
Finn

Modify relationship data before inserting/creating

So I do have a resource, with a form with multiple text inputs. In that form I made a fieldset that links to a relation
Forms\Components\Fieldset::make(self::$relationName)
->relationship(self::$relationName)
->label('Pagina informatie')
->schema([
Forms\Components\TextInput::make('meta_title')
->label('Meta title')
->required(),
Forms\Components\TextInput::make('meta_description')
->label('Meta description')
->required(),
])
Forms\Components\Fieldset::make(self::$relationName)
->relationship(self::$relationName)
->label('Pagina informatie')
->schema([
Forms\Components\TextInput::make('meta_title')
->label('Meta title')
->required(),
Forms\Components\TextInput::make('meta_description')
->label('Meta description')
->required(),
])
As you can see, in there I have 2 inputs in there. Now when I click on create in Filament, I want to modify the data from the text input. Normally I would modify the data in the app\Filament\Resources\MyResource\Pages\CreateMyResourcePage.php using the mutateFormDataBeforeCreate(array $data) method. But in the $data of the mutateFormDataBeforeCreate method, I do not have access to the relationship properties <a:aPES_Think:493353113332219924> So how would I modify it?
2 Replies
wyChoong
wyChoongβ€’2y ago
->mutateRelationshipDataBeforeCreateUsing(fn() => your code) to the fieldset
Finn
FinnOPβ€’2y ago
Thanks! I will try this when I am at my laptop πŸ‘
Want results from more Discord servers?
Add your server