How do I make a relationship optional?
I have a fieldset with multiple select fields. I want to make sure the relationship is not saved if all the fields inside the fieldset are empty. However, currently Filament is trying to create an empty record for the salary relation. How do I avoid that?
Solution:Jump to solution
I think there is a
saveRelationshipsUsing()
or similar method you could use9 Replies
->nullable()
?
Ah it's a Fieldset. Not sure whether that works πYeah, that method doesn't exist on Fieldset.
I tried
->dehydrated(true)
and that doesn't work as wellIt should be
->dehydrated(false)
if you don't want to save it
But then you need to pass a condition via a closureDoesn't work. It still tries to create a record with empty values.
Solution
I think there is a
saveRelationshipsUsing()
or similar method you could useIs there an example for that in the docs?
I have no idea, sorry.
I think I fixed it using the
saveRelationshipsUsing
method:Maybe wanna use
filled()
instead of isset()
to filter blank states