Customizing option label from select with relationship

Forms\Components\Select::make('product_id')
->label('Product')
->relationship('product', 'name', fn (Builder $query) => $query->withTrashed())
->searchable()
Forms\Components\Select::make('product_id')
->label('Product')
->relationship('product', 'name', fn (Builder $query) => $query->withTrashed())
->searchable()
Since the relationship includes trashed products, how to modify the option label from e.g: Laptop to Laptop (archived)for trashed products?
1 Reply
awcodes
awcodes2y ago
->getOptionLabelFromRecordUsing(fn (Model $record) => $record->name . $record->deleted_at ? " (Archived)" : null)
->getOptionLabelFromRecordUsing(fn (Model $record) => $record->name . $record->deleted_at ? " (Archived)" : null)
Something like that probably.
Want results from more Discord servers?
Add your server