Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the MySQL JSON column is not contains the value in laravel?

I used to find whether the searching item is exist in the JSON datatype column or not.

I use,

 TABLE::whereRaw('json_contains(list, \'["value"]\')')->get();

this to return those are having the "value" in "list" JSON column.

But, how can i use reverse method to list, those are not having this value in json column in laravel.

Thank you !

like image 317
Shankar Thiyagaraajan Avatar asked Jun 01 '17 10:06

Shankar Thiyagaraajan


2 Answers

You can use not:

TABLE::whereRaw('not json_contains(list, \'["value"]\')')->get();

In Laravel 5.6.24 you can use whereJsonDoesntContain():

TABLE::whereJsonDoesntContain('list', 'value')->get();
like image 170
Jonas Staudenmeir Avatar answered Oct 04 '22 00:10

Jonas Staudenmeir


DB::table('table')->whereNull('list->key')->get();

like image 29
lucidlogic Avatar answered Oct 04 '22 00:10

lucidlogic