F
Filament10mo ago
Xavi

How to set selected on edit form

I have this field
Forms\Components\Select::make('billing')
->label(__('Datos de facturación'))
->options(function (RelationManager $livewire): array {
return $livewire->ownerRecord->billings
->pluck('name', 'id')
->toArray();
})
->searchable()
->required()
Forms\Components\Select::make('billing')
->label(__('Datos de facturación'))
->options(function (RelationManager $livewire): array {
return $livewire->ownerRecord->billings
->pluck('name', 'id')
->toArray();
})
->searchable()
->required()
How can i set selected value on edit form (its a relationmanager), searching on user_billings table?? I try adding this
->formatStateUsing(function (UserInvoice $record, RelationManager $livewire): ?int {
return $livewire->ownerRecord->billings->where('nif', $livewire->ownerRecord->nif)->first()?->id;
})
->formatStateUsing(function (UserInvoice $record, RelationManager $livewire): ?int {
return $livewire->ownerRecord->billings->where('nif', $livewire->ownerRecord->nif)->first()?->id;
})
But it doesn't works Thanks
3 Replies
toeknee
toeknee10mo ago
or formatStateUsing ?
->formatStateUsing(fn($state, $record) => !empty($state) ?? // Go fetch it here // )
->formatStateUsing(fn($state, $record) => !empty($state) ?? // Go fetch it here // )
Xavi
XaviOP10mo ago
I use mountUsing and works perfect!!! thanks!
Want results from more Discord servers?
Add your server