Show name instead of id in Select relationship field, upon record soft deletion.
When I have a Select field like so:
My field shows the group names in the selection options, and when a resource record is created, the product name is also shown in the Select field in the edit form. See first screenshot.
If I delete the product that was selected, the Select field in the edit form shows the id of the previously existing product instead of the it's name. See second screenshot.
I understand that the non-exising product should not be selectable after it is deleted, but I would love to be able to show the product name instead of the id, when the product has been deleted.
Is there a way to force Filament Select fields to use name instead of id in relationships, or do something else that achieves what I want to do?
Solution:Jump to solution
I think what I want to implement is not possible, as the field just shows what is saved in the pivot table record in the database, which is the product_id. So to avoid showing product id's in case the products have been removed, I added a static
product_name
field to my pivot table, and added this to my filament form, which gets set in mutateRelationshipDataBeforeCreateUsing()
. Then I show the Select relationship product_id
field or the product_name
conditionally, based on the $record
...7 Replies
$query
...
->withTrashed()
?hi; out of ur question ; whats $get('../../meal_type_id') ???
can u explain it pls
This doesn't block soft deleted records from being selectable, so this doesn't solve it.
Solution
I think what I want to implement is not possible, as the field just shows what is saved in the pivot table record in the database, which is the product_id. So to avoid showing product id's in case the products have been removed, I added a static
product_name
field to my pivot table, and added this to my filament form, which gets set in mutateRelationshipDataBeforeCreateUsing()
. Then I show the Select relationship product_id
field or the product_name
conditionally, based on the $record
and the status_id
. This works for me, as the order items product fields should not be editable after an order deadline has passed, so the order items become disabled informative fields in the edit form.More info about that here:
https://discord.com/channels/883083792112300104/1213970986534314014
My final function/solution is here: