How to determine if JSON value and parameter are not equal in Laravel?
P粉250422045
P粉250422045 2023-08-26 23:37:58
0
1
614
<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>
P粉250422045
P粉250422045

reply all(1)
P粉256487077

You must try this

$records = DB::table('atble')->select('res_id',
'msg_string')->where('res_id',
$param)->whereJsonContains('ret_string->msg', ['object_key' => 'object_value'])->latest()->first();

Also follow the correct guidelines for WhereJsonContains

You can also refer to this linkfor more help

Here is an example, it will help you.

$array = [0 => 1, 1 => 2, 2 => 3];

// Eloquent
PaymentTransaction::whereJsonContains('payload->ProductCode- >id',$array)->get();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!