F
Filament16mo ago
Mdk

Show related entity's details in an RelationManager edit modal

I have 3 entities, Customer, Product and Wishlist, with the latter having both product_id and customer_id in it I'm trying to show a customer's wishlist in its details page, which works fine inside the RelationManager table by just using product.title and product.price, but when I go edit this relation those 2 fields are emtpy (while other fields that are directly on the wishlist table are shown fine) What am I missing here? Why does it work in the table but not in the form?
Solution:
I managed to get it working by doing this: ```Forms\Components\TextInput::make('product.lowest_price') ->loadStateFromRelationshipsUsing(function($record, $component) { $component->state($record->product->lowest_price); })...
Jump to solution
3 Replies
Mdk
MdkOP16mo ago
this also happens in non-relationmanager edit/view pages as well, apparently it's not loading the relation correctly? Ok, I could fix showing the product title by using select::relationship, which is fine, but what about the price, since that isn't a related item but rather a property of the product?
Patrick Boivin
Patrick Boivin16mo ago
Can you share the code of your relation manager? Specifically the table and custom action.
Solution
Mdk
Mdk16mo ago
I managed to get it working by doing this:
Forms\Components\TextInput::make('product.lowest_price')
->loadStateFromRelationshipsUsing(function($record, $component) {
$component->state($record->product->lowest_price);
})
->disabled()
->numeric(),
Forms\Components\TextInput::make('product.lowest_price')
->loadStateFromRelationshipsUsing(function($record, $component) {
$component->state($record->product->lowest_price);
})
->disabled()
->numeric(),
Want results from more Discord servers?
Add your server