F
Filament5mo ago
xfly

Get relationship in select

a user hasOne profile, how can i show the user.profile.first_name and user.profile.last_name instead of the 'name' of the users table? public static function form(Form $form): Form { return $form ->schema([ Forms\Components\Select::make('status') ->options(ProcessStatus::class), Forms\Components\Select::make('user_id') ->label('User') ->options(User::all()->pluck('name', 'id')) ]); }
2 Replies
Tobias Platen
Tobias Platen5mo ago
Maybe not the simplest or most ideal way, but it works.
->options(
User::all()
->each(function(User $user) {
$user->full_name = $customer->first_name . ' ' . $customer->last_name;
})
->pluck('full_name', 'id'))
->options(
User::all()
->each(function(User $user) {
$user->full_name = $customer->first_name . ' ' . $customer->last_name;
})
->pluck('full_name', 'id'))
when your database implements concat()
->options(
User::selectRaw('id, CONCAT(first_name, \' \', last_name) as full_name')
->get()
->pluck('full_name','id'))
->options(
User::selectRaw('id, CONCAT(first_name, \' \', last_name) as full_name')
->get()
->pluck('full_name','id'))
xfly
xfly5mo ago
thank you