How to determine if JSON value and parameter are not equal in Laravel?
P粉250422045
2023-08-26 23:37:58
<p>I want to get those records from the database that are not equal to "My Msg". </p>
<p>The JSON in my database column is as follows:</p>
<pre class="brush:php;toolbar:false;">`{
"msg": "My Msg",
"resource_id": "Resourse"
}`</pre>
<p>I tried <code>JSON_EXTRACT</code> and <code>whereJsonContains</code></p>
<p>But no luck, I'm using Laravel 8 with MySQL. </p>
<p>The query is as follows:</p>
<pre class="lang-php prettyprint-override"><code>$records = DB::table('atble')->select('res_id',
'msg_string')->where('res_id',
$param)->whereJsonContains('ret_string->msg',
['elem1','elem2'...])->latest()->first();
</code></pre>
<p>The above query gave me no results. </p>
<p>Any help would be greatly appreciated. </p>
You must try this
Also follow the correct guidelines for WhereJsonContains
You can also refer to this linkfor more help
Here is an example, it will help you.