I have a simple json table containing an array of values:
[1,2,3,4,5,6,7,8,9]
I’m trying to query this table by multiple conditions:
- Must contain the value
2
- Must contain atleast 3 of the other values, it does not matter which ones
This is what I currently have:
$data= Model::whereJsonContains('my_column', [2])->get();
This works for condition 1, now I can’t seem to figure out how to include condition 2 as well.
2
Answers
Assuming your JSON array has unique values, you can use
whereJsonLength
to count the size of the JSON array like below: