© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
9 replies
nowak

Show name instead of id in Select relationship field, upon record soft deletion.

When I have a Select field like so:
Select::make('product_id')
                    ->label('Product')
                    ->relationship('product', 'name', function (Builder $query, Get $get) {
                        $mealTypeId = $get('../../meal_type_id');
                        $query->byMealType($mealTypeId);
                    })
                    ->preload() 
                    ->required()
                    ->distinct()
                    ->disableOptionsWhenSelectedInSiblingRepeaterItems()
                    ->columnSpan([
                        'md' => 5,
                    ])
                    ->searchable(),
Select::make('product_id')
                    ->label('Product')
                    ->relationship('product', 'name', function (Builder $query, Get $get) {
                        $mealTypeId = $get('../../meal_type_id');
                        $query->byMealType($mealTypeId);
                    })
                    ->preload() 
                    ->required()
                    ->distinct()
                    ->disableOptionsWhenSelectedInSiblingRepeaterItems()
                    ->columnSpan([
                        'md' => 5,
                    ])
                    ->searchable(),


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?
image.png
image.png
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
product_name
field to my pivot table, and added this to my filament form, which gets set in
mutateRelationshipDataBeforeCreateUsing()
mutateRelationshipDataBeforeCreateUsing()
. Then I show the Select relationship
product_id
product_id
field or the
product_name
product_name
conditionally, based on the
$record
$record
and the
status_id
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.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to get name instead of id in a select with relationship
FilamentFFilament / ❓┊help
3y ago
Change case of relationship name field in a select
FilamentFFilament / ❓┊help
3y ago
select field display id of record in edit page
FilamentFFilament / ❓┊help
2y ago
Filament Action: Select field shows ID instead of name when filling form
FilamentFFilament / ❓┊help
5mo ago