filament select with two columns

1.3k Views Asked by At

How could you configure the filament select component so that I get the first and last name?

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Select::make('customer_id')
                    ->relationship('customer', 'name')
                    ->searchable(['name', 'surname'])
                    ->preload()
                    ->required()
                    ->createOptionForm([
                        TextInput::make('name')
                            ->required()
                            ->label('Nombre'),
                        TextInput::make('surname')
                        ->required(),
                        TextInput::make('lastname')
                        ->label('Last Name')
                    ]),
            ]);
    }

I tried with an array but it doesn't work

->relationship('customer', ['name', 'lastname'])

1

There are 1 best solutions below

0
Muntadher On

You can ues this function formatStateUsing(), like this example:

Tables\Columns\TextColumn::make('first_name')
    ->label(__('student.full_name'))
    ->formatStateUsing(function ($state, \App\Models\Student $student) {
        return $student->first_name . ' ' . $student->last_name;
}),