Form save relationship with other belongs to (user_id.etc) how?
Let's save I have a Filament form that is supposed to create a
Book
record.
The books
table has user_id
Then in it I have a repeater field that allow me to create BookChapter
records
On my book_chapters
tables I have book_id
and user_id
In my submit()
code I have something like this
It is in the second line I have issue, because user_id is not passed into my relationship models (book chapters, media.etc). Only book_id
is filled
How do i do so in a clean way? I thought about adding a hidden user_id field to my repeaters / spatie media uploads.etc but there is a risk of user manipulating the browser DOM before submission and what if what I need to do is not user_id?
Thank you5 Replies
there is a mutateRelationshipDataBeforeCreateUsing() on the repeater I think which you can use to set book_id
saveRelationships() will set the book_id so i assume this is for user_id and other foreign ids?
is this an admin only method or filament forms can use it too?
->mutateRelationshipDataBeforeCreateUsing()
can be chained onto the Repeaterwhat's the difference between
this and mutateRelationshipDataBeforeFillUsing and mutateRelationshipDataBeforeSaveUsing?
One modifies it before filling the form and one modifies it before saving the form.