Empty hidden fields
I have two columns in my table
hours
and semesters
. both are nullable.
in my form, I have a checkbox, it's value decides whether to show the hours or the semesters input using the ->hidden
method
now I don't want both semesters and hours to be set at the same time, so for example if horus
is shown I want to make sure semesters
is null when saving the form and vice-verca2 Replies
In your relationship, you can pass a condition to only save it if it's not empty: ->relationship('relationship-field',
condition: fn (?array $state): bool => filled($state['field-name']))
Multiple ways to go about this. On toggle you could set ‘the other value’ to null or on submit you could check the toggle and set the other value to null. What I also always like to do is self validate the model for this case, so that if whatever possible edge case / bug occurs the model can’t be saved.