[英]How can I use wherejsoncontains when table column has array of objects with same keys and different values laravel php
Am trying to get check whether the data with condition exists in the column which is in json format as below.我正在尝试检查具有条件的数据是否存在于 json 格式的列中,如下所示。
Am having 2 columns id,test_data我有 2 列 id,test_data
In test_data column it has below jsonvalue在 test_data 列中,它的 jsonvalue 低于
{"test_info":[{"type":"text","name":'sam',"contact":9839383333,"applicant":1,"email":sam93@gmail.com,"address":"newyork"}, {"type":"textarea","name":'john',"contact":383839283,"applicant":0,"email":"john33@gmail.com","address":"california"}]} {"test_info":[{"type":"text","name":'sam',"contact":9839383333,"applicant":1,"email":sam93@gmail.com,"address":" newyork"}, {"type":"textarea","name":'john',"contact":383839283,"applicant":0,"email":"john33@gmail.com","address":"加州"}]}
Am trying to check where the data with name='sam' and type='text'exists in data or not.我正在尝试检查 name='sam' 和 type='text' 的数据是否存在于数据中。 Have tried below once but its not working for the array of objects在下面尝试过一次,但它不适用于对象数组
TestData::select('id')->WhereJsonContains('test_data->test_info->type', ["text"]);
but the above one doesnot work as the column contains array of objects.但上述一个不起作用,因为该列包含对象数组。 how can I check whether the data is present or not.如何检查数据是否存在。
Just replace只需更换
test_data->test_info->type
with和
test_info[0]['type']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.