0

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:

  1. Must contain the value 2
  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.

1

1 Answer 1

1

Assuming your JSON array has unique values, you can use whereJsonLength to count the size of the JSON array like below:

$data = Model::whereJsonContains('my_column', 2)
              ->whereJsonLength('my_column', '>', 3)
              ->get();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.