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?
33 Replies
?
doesn't work
That's the problem: it doesn't work (at least for me).
what is the issue?
are the tags showing on the table?
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.
weird..what is the filament version?
I have just done an update, the latest v3.0.15, still not working.
depraced?
did you try my code?
Does it work that way for you?
should work as well
I have a tag column and it is working here.. it is a json column as well
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.
@qcol74 Can you try
php artisan view:clear
?
Sometimes its the cacheok if it doesn't work, share the code
In the old docs it says you need to cast the tags column. Not sure if this is needed on TextColumn
Yes I Have casts
the search should work without it
Can you please try this? If not please share the whole class
Unfortunately, it did not help.
Please share your full code and the value from your database
1. phpMyAdmin
2. Filament
3. code
result
What is your cast?
try set "esd" and search for esd (lowercase)
does not work either
Solution
try this:
Yes, i found problem
Filament converts TAG to lower case in the query
Yes Leandro... now it works!
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}%");
})
yep it was a test actually... you can use
->whereRaw(..)
as well