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()
4 Replies
https://filamentphp.com/docs/3.x/tables/columns/getting-started#searching
->searchable(query: function (Builder $query, string $search)
?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}%");
})
I ended up making a filter to solve the issue:
SelectFilter::make('id')->label('Titulo')
->options(LaboralDocument::all()->pluck('title', 'id'))
->searchable()
->preload()
Instead simple
title
use translation.title
Tables\Columns\TextColumn::make('translation.title')->searchable()