F
Filament17mo ago
lazydog

Table Filter multiple columns

How can I append 2 values/fields in Select filter? Currently I can only append one field to my filter.
5 Replies
lazydog
lazydogOP17mo ago
I wan to appear first_name and last_name fields from db, but I can only appear first_name. May I know how can I do this?
SelectFilter::make('employee_id')
->label('Employee')
->relationship('employee', 'first_name')
->searchable()
SelectFilter::make('employee_id')
->label('Employee')
->relationship('employee', 'first_name')
->searchable()
JibayMcs
JibayMcs17mo ago
In your Employee model create a custom attribute to bind a full_name like this.
public function getFullnameAttribute() {
return "$this->first_name $this->last_name";
}
public function getFullnameAttribute() {
return "$this->first_name $this->last_name";
}
And call "full_name" in your relation ->relationship('employee', 'full_name') I don't remember, the case in the method name, but switch between getFullnameAttribute() and getFullNameAttribute, to create fullname or full_name custom attribute.
Kenneth Sese
Kenneth Sese17mo ago
The recommended way in the docs: If you'd like to customize the label of each option, maybe to be more descriptive, or to concatenate a first and last name, you should use a virtual column in your database migration: $table->string('full_name')->virtualAs('concat(first_name, \' \', last_name)'); Select::make('authorId') ->relationship('author', 'full_name')
lazydog
lazydogOP17mo ago
Thanks @kennethsese and @jibaymcs for your suggestion. I think, Archilex suggestion is better, working and I found it in docs .
Want results from more Discord servers?
Add your server