selectfilter from json data
I have a database filed where i have saved something like this:
Cane be one o n lines.
Now i need a SelectFilter where i can choose a language. And language_level (or language_level) withou selection.
I try:
`
but get error: Unable to resolve dependency [Parameter #1 [ <required> $value ]] in class App\Filament\Resources\ApplicantResource
20 Replies
Did you resolve this as I see it is ticked resolved?
no sorry, its NOT resolved. i just edited it.
Can u elaborate ur question more? I am not able to understand what u r looking for.
Sure, sorry: I have a database field 'languages', where i have saved on or several json strings, like the above ones. they contain the languae, an applicant speaks, and also the level. It can be 1 to n lines. But at least one.
No i want to create in my ApplicantsResource in the table view a Filter, where i can select a language. F.E. french, so that the list will show only the applicants which have french in their language field.
I am struggling with the json string. I dont get the language out of the stron to compare it with teh selected language in the dropdown list. I thougt i can do it with somehtin like
`
but i cant get it to work.
Yeah that's a bit of a tricky scenario, most people would say them as individual database values indexed of the language
Try this one
Or this one,
if i do:
`
i get the error:
`
😦
Solution
Try
$state
instead of $value
@pboivin error is gone! thanks 🙂 yesss
But i have still the problem, that the filter is not working:
My table field languages can look like this:
`
or like this
`
1-n languages and language-levels.
I am using:
`
The table list is emptry from the beginning. And when i select a language, it still keeps empty. No error message.
In this example you want all applicants with a
{"language":"german", ...}
entry?At the end i resolved it this way:
`
Thanks for all your help!!
yes @pboivin
Are you using mysql?
yes
and mariadb on production
On production with mariadb i get now the error SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION humres.JSON_CONTAINS does not exist
Ok, different issues 😅
What's your mysql version?
mysql Ver 8.0.29 for macos12 on x86_64 (MySQL Community Server - GPL)
i solved it now for my mac and the production server this way:
`
I mean, yeah, that's not a bad solution if the JSON is always formatted without any whitespaces
for any more elegant solution i would be very thankfull. But is has to work on maria db.
yes, thats the case.
(not sure about which version of MariaDB would be needed....)
ChatGPT4 says: In this example, we're using MySQL's JSON_CONTAINS function which returns 1 if a JSON document contains a specified value. Note that this will only work if you're using MySQL 5.7.8 or higher or MariaDB 10.2.3 or higher. This is because the JSON_CONTAINS function was added in these versions.
I would double-check that but it's probably right 🙂
Ok I'm not super experienced with JSON columns... I did a quick test just out of curiosity and this seems to work:
It's not that much better than your solution above, but it'll search only in the combined values of
languages.*.language
instead of the entire column.Hey @pboivin great. Thanks very much! :)_
you are completely right 🙂 haha. i had to do several intents.