© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
17 replies
matin rajabi

select field display id of record in edit page

hello guys i have a form with a select option field like this:

Select::make('variety_detail_id')
                                ->options(
                                    function (callable $get) {
                                        if ($get('product_id')) {
                                            $category_id = Product::where(['id' => $get('product_id')])->get()[0]['category_id'];
                                            $variety_id = Category::where('id', $category_id)->get()[0]['variety_id'];
                                            return VarietyDetail::where('variety_id', $variety_id)->get()||->pluck('value', 'id')||;
                                        }

                                    }
                                )
Select::make('variety_detail_id')
                                ->options(
                                    function (callable $get) {
                                        if ($get('product_id')) {
                                            $category_id = Product::where(['id' => $get('product_id')])->get()[0]['category_id'];
                                            $variety_id = Category::where('id', $category_id)->get()[0]['variety_id'];
                                            return VarietyDetail::where('variety_id', $variety_id)->get()||->pluck('value', 'id')||;
                                        }

                                    }
                                )


i set a label for each option but in edit page it doesn't have any label, so display its id like in the image

what should i do for this?
image.png
Solution
You would add the relationship then follow the documentation:

https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-query

Select::make('product_id')
    ->relationship(
        name: 'product_options',
        titleAttribute: 'title',
        modifyQueryUsing: fn (Builder $query) => $query->with('categories')->whereHas('categories.variety_id'),
    )
    ->getOptionLabelFromRecordUsing(fn ($record) => "{$record->title} ({$record->myRelation->count()})")
Select::make('product_id')
    ->relationship(
        name: 'product_options',
        titleAttribute: 'title',
        modifyQueryUsing: fn (Builder $query) => $query->with('categories')->whereHas('categories.variety_id'),
    )
    ->getOptionLabelFromRecordUsing(fn ($record) => "{$record->title} ({$record->myRelation->count()})")


or similar depending on your code
Select - Form Builder - Filament
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

Select Field empty on Edit Page
FilamentFFilament / ❓┊help
2y ago
Select Field relationship on edit page
FilamentFFilament / ❓┊help
2y ago
Avoid ID in edit page
FilamentFFilament / ❓┊help
16mo ago
Column 'id' in where clause is ambiguous in edit record page
FilamentFFilament / ❓┊help
2y ago