Editing a Relationship

I have a form that contains a related record for which I want to submit data at the same time. For this I have set up:
Forms\Components\Section::make()
->relationship('foo')
->schema([...]);
Forms\Components\Section::make()
->relationship('foo')
->schema([...]);
I need to perform a mutation to add extra data when saving, but I can't find a way to do this on the relationship. Does anyone have any suggested on how I can achieve this?
1 Reply
SonjaTuro
SonjaTuroOP11mo ago
It turns out there was a flaw in my thinking about the record relationship: Even though I was peforming a main record edit, the relationship didn't exist yet, and was therefore calling a different function to what I was expecting:
Forms\Components\Section::make()
->relationship('foo')
->schema([...])
->mutateRelationshipDataBeforeCreateUsing(
function (array $data) : array {
$data['subtype'] = 'main';
return $data;
});
Forms\Components\Section::make()
->relationship('foo')
->schema([...])
->mutateRelationshipDataBeforeCreateUsing(
function (array $data) : array {
$data['subtype'] = 'main';
return $data;
});
This is correct approach for a new relation, where I was incorrectly using mutateRelationshipDataBeforeSaveUsing which only works when the relation already exists.
Want results from more Discord servers?
Add your server