F
Filament5mo ago
V01D

Searchable translatable column

Hi guys, I'm using a translation package (astrotomic) and I'm trying to make a column searchable, but it says it can't find the column, this is because that field is in the translations table and not in the resource model table . How can I modify the searchable function to do a join or something? Tables\Columns\TextColumn::make('title')->searchable()
No description
4 Replies
V01D
V01D5mo ago
thx, i'm trying this solution but it seems still doesn't work: Tables\Columns\TextColumn::make('title')->searchable(query: function (Builder $query, string $search): Builder { return $query->join('laboral_document_translation', 'laboral_document.id', '=', 'laboral_document_translation.laboral_document_id') ->where('laboral_document_translation.title', 'like', "%{$search}%"); })
No description
V01D
V01D5mo ago
I ended up making a filter to solve the issue: SelectFilter::make('id')->label('Titulo') ->options(LaboralDocument::all()->pluck('title', 'id')) ->searchable() ->preload()
Oleksandr Moik
Oleksandr Moik4mo ago
Instead simple title use translation.title Tables\Columns\TextColumn::make('translation.title')->searchable()