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')||; } } )

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()})")


or similar depending on your code
Was this page helpful?