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:
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.
Jump to solution
7 Replies
awcodes
awcodes9mo ago
Only thing I can think of is pulling it off of the livewire’s form data.
binaryfire
binaryfireOP9mo ago
Do you have an example snippet you could share? Not exactly sure how I'd do that.
awcodes
awcodes9mo ago
$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.
binaryfire
binaryfireOP9mo ago
Ok thanks, will give that a try. Couldn't figure it out from the source code this time around. I'll take another look
awcodes
awcodes9mo ago
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
awcodes
awcodes9mo ago
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.
binaryfire
binaryfireOP9mo ago
Yeah, $component is returning the pivot model for each individual item. So I can use that to get the underlying related model. Cool, thanks!
Want results from more Discord servers?
Add your server