Json OrWhere with other Filters ?

Suggestions on how to perform a subquery with a json field for multiple responses? I'm currently running into something like this: Company table - json field with attributes for type of activities a business is interested in. I want to be able to select something - like say a region where a company is as a filter (which works) but then say interested in team building, or direct sales, or whatever . . . but I want the businesses that have team building and I want the ones that have said direct sales. My filter should be an orwhere but it's against the json field.
4 Replies
toeknee
toeknee2y ago
You should be able to use whereJsonContains depending on your database version. see:https://stackoverflow.com/questions/53641403/search-in-json-column-with-laravel with a custom query
Stack Overflow
Search in Json column with Laravel
In my emails table, I have a column named To with column-type Json. This is how values are stored: [ { "emailAddress": { "name": "Test", "address": "test@examp...
HeartlandTechie
HeartlandTechieOP2y ago
The issue isn’t the json, it is adding additional filters not related to that column and selecting multiple potential json values. Like this:
select count(*)from businesses where current_status = 'Accepted' and json_search(pathways_interest,'one','ble') and (json_search(involvement_interest,'one','Guest Speaker') or json_search(involvement_interest,'one','Job Shadow'))
LeandroFerreira
what about whereRaw()? Something like this:
whereRaw('json_contains(pathways_interest, \'["one", "ble"]\')')
whereRaw('json_contains(pathways_interest, \'["one", "ble"]\')')
HeartlandTechie
HeartlandTechieOP2y ago
I really need to have that portion of the filter be or where with mutiples . . . because they could specify multiple involvement interests - the list should be additive
Want results from more Discord servers?
Add your server