Accessing related $record(s) in hasMany repeaters
Hi all
I have a repeater that uses a hasMany relationship (via a pivot model). I need to access each item's record inside the header action closures. Any idea how I can do that?
Thanks!
Solution:Jump to solution
If it’s before the record is saved you have to get it from the form state, if not it already exists on the record via the relationship.
7 Replies
Only thing I can think of is pulling it off of the livewire’s form data.
Do you have an example snippet you could share? Not exactly sure how I'd do that.
$livewire is available in most callbacks. Dd or ray until you find what you need. Definitely not a common use case but I think it can be done. Don’t be afraid to source dive the filament code.
Ok thanks, will give that a try. Couldn't figure it out from the source code this time around. I'll take another look
If it’s a relationship though there’s nothing stopping you from just directly pulling them off the model either.
Assuming you have the model at this particular point in time.
Solution
If it’s before the record is saved you have to get it from the form state, if not it already exists on the record via the relationship.
Yeah, $component is returning the pivot model for each individual item. So I can use that to get the underlying related model. Cool, thanks!