FormatUsingState is null on a select relationship

Forms\Components\Select::make('sponsor_id')
->relationship('sponsor', 'first_name')
->native(false)
->formatStateUsing(function ($state, $record) {
//console.log($record);
dd($state);
return $record->first_name . ' ' . $record->second_name;
})
->label("Sponsor Name")
->searchable()
->preload(),
Forms\Components\Select::make('sponsor_id')
->relationship('sponsor', 'first_name')
->native(false)
->formatStateUsing(function ($state, $record) {
//console.log($record);
dd($state);
return $record->first_name . ' ' . $record->second_name;
})
->label("Sponsor Name")
->searchable()
->preload(),
2 Replies
David Vincent
David Vincent8mo ago
As mentioned in the doc, you should use ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->first_name} {$record->last_name}")
codeartisan
codeartisanOP8mo ago
Thank you solved
Want results from more Discord servers?
Add your server