简体   繁体   English

当表列具有具有相同键和不同值的对象数组时,如何使用 wherejsoncontains laravel php

[英]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.

相关问题 PHP,对象数组,如何使用一组对象值作为数组键 - PHP, array of objects, how can I use one set of object values as the array keys 我有一个下面的数组,其中一些相同的键具有不同的值。 如何在PHP中将相同的键值与此键组合? 我正在使用WAMP,Codeigniter - I have a below array with some same keys with different values. How can I combine same keys values with that key in PHP? I am using WAMP, Codeigniter 如何使用数组值作为键? - How can I use array values as keys? PHP在不同的数组键中搜索相同的值 - Php search same values in different array keys 如何将 array_map 与键和值一起使用,但返回具有相同索引(不是 int)的数组? - How can I use array_map with keys and values, but return an array with the same indexes (not int)? PHP CodeIgniter-关系表时如何获得良好的结果数组(不同表中的列名称相同) - PHP CodeIgniter - how to get good result array when relational table (there are same column name in different table) 我如何只显示具有相同列值的值laravel 5 - How can I only display values that has the same column value laravel 5 如何在保持键相同的情况下旋转数组的值? 的PHP - How can I rotate the values of an array whilst keeping the keys the same? PHP 如何连接具有相同键但不同值的数组? - How to concatenate an array with the same keys but different values? 我如何使用数组中的值? (PHP) - how can i use values in array ? (php)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM