Reputation: 638
Seofilter db table has json column named category_ids. I wanna query where value exists in json col.
And not querying all the row and get their jsoncol value then explode etc, I wanna do it with less query to server because of server loads.
for example [{60, 59, 57}] or [{55, 58, 60}] so 60 exists both of them.
Upvotes: 1
Views: 1847
Reputation: 25936
Laravel 5.6.24 includes whereJsonContains()
:
DB::table('seofilter')->whereJsonContains('category_id', 60)->get();
DB::table('seofilter')->whereJsonContains('category_id', [60, 61, ...])->get();
Upvotes: 2
Reputation: 917
MySQL has a group of JSON manipulating and searching function i believe you are going to find what you want over here start with JSON_CONTAINS
https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-contains
which clearly fits the example you provided .
Upvotes: 0