F
Filament16mo ago
qcol

TagsColumn searchable()?

I am trying to use the TagsInput field but in such a way that I can filter or search for records by tag. TagsColumn::make('tags')->separator(',')->searchable() doesn't work - it doesn't search for records with tags. Also, TagsColumn is marked as 'depraced'. I also don't see in the documentation the use of a filter with tags, the only example on Discord I can find is for spatie-tags. So should I use spatie-tags to be able to filter data by tags?
Solution:
try this: ```php TextColumn::make('tags') ->badge() ->separator(',')...
Jump to solution
33 Replies
LeandroFerreira
LeandroFerreira16mo ago
TextColumn::make('tags')
->badge()
->separator(',')
->searchable()
TextColumn::make('tags')
->badge()
->separator(',')
->searchable()
?
qcol
qcolOP16mo ago
doesn't work That's the problem: it doesn't work (at least for me).
LeandroFerreira
LeandroFerreira16mo ago
what is the issue? are the tags showing on the table?
qcol
qcolOP16mo ago
It simply does not search for records. I enter a TAG in the search field and it does not search for records that contain that TAG. Yes, the TAG appears both in the table and works correctly in the form.
LeandroFerreira
LeandroFerreira16mo ago
weird..what is the filament version?
qcol
qcolOP16mo ago
I have just done an update, the latest v3.0.15, still not working.
qcol
qcolOP16mo ago
depraced?
LeandroFerreira
LeandroFerreira16mo ago
did you try my code?
qcol
qcolOP16mo ago
Does it work that way for you?
LeandroFerreira
LeandroFerreira16mo ago
should work as well I have a tag column and it is working here.. it is a json column as well
qcol
qcolOP16mo ago
Oh, sorry. I hadn't noticed that there was a TextColumn in yours. Unfortunately after replacing it still doesn't work. Does it work that way for you? Hmmm... OK, so something is wrong with me. I am therefore looking for the cause. Thank you.
Matthew
Matthew16mo ago
@qcol74 Can you try php artisan view:clear? Sometimes its the cache
LeandroFerreira
LeandroFerreira16mo ago
ok if it doesn't work, share the code
Thijmen
Thijmen16mo ago
In the old docs it says you need to cast the tags column. Not sure if this is needed on TextColumn
qcol
qcolOP16mo ago
Yes I Have casts
LeandroFerreira
LeandroFerreira16mo ago
the search should work without it
Matthew
Matthew16mo ago
Can you please try this? If not please share the whole class
qcol
qcolOP16mo ago
Unfortunately, it did not help.
Thijmen
Thijmen16mo ago
Please share your full code and the value from your database
qcol
qcolOP16mo ago
qcol
qcolOP16mo ago
1. phpMyAdmin 2. Filament 3. code
qcol
qcolOP16mo ago
result
Thijmen
Thijmen16mo ago
What is your cast?
qcol
qcolOP16mo ago
LeandroFerreira
LeandroFerreira16mo ago
try set "esd" and search for esd (lowercase)
qcol
qcolOP16mo ago
does not work either
Solution
LeandroFerreira
LeandroFerreira16mo ago
try this:
TextColumn::make('tags')
->badge()
->separator(',')
->searchable(query: function (Builder $query, string $search): Builder {
$search = Str::upper($search);
return $query->where('tags', 'like', "%{$search}%");
})
TextColumn::make('tags')
->badge()
->separator(',')
->searchable(query: function (Builder $query, string $search): Builder {
$search = Str::upper($search);
return $query->where('tags', 'like', "%{$search}%");
})
qcol
qcolOP16mo ago
Yes, i found problem
qcol
qcolOP16mo ago
qcol
qcolOP16mo ago
Filament converts TAG to lower case in the query Yes Leandro... now it works!
qcol
qcolOP16mo ago
Thank you very much for your time. I think it's a bug? I'll report it on github. Your solution, on the other hand, will not work on lowercase tags. This works with any letter size: TextColumn::make('tags') ->badge() ->separator(',') ->searchable(query: function (Builder $query, string $search): Builder { $search = Str::lower($search); return $query->where(DB::Raw('LOWER(tags)'), 'like', "%{$search}%"); })
LeandroFerreira
LeandroFerreira16mo ago
yep it was a test actually... you can use ->whereRaw(..) as well
Want results from more Discord servers?
Add your server