3

I've asked this in Laracasts but I have yet to receive an answer to this question. I have seen this stackoverflow post: Laravel Eloquent - Working with an array of JSON objects

Simply put, I would like to know if there is a way for me to use:

->whereJsonContains('column', ['starts_at' => '2018-11-24 08:00:00'])

but instead of just one value, I'd like to compare it to an array of values, i.e:

$dates = ['2018-11-24 08:00:00', '2020-19-01 08:00:00'];

->whereJsonContains('column', ['starts_at' => $dates])

I am fully aware that this does not work because whereJsonContains only supports comparing one value instead of an array, so I figured I needed to combine this with the method whereIn. However, I am unable to accomplish this.

Any help will be fully appreciated. Thank you very much!

1 Answer 1

7

Use multiple orWhereJsonContains() constraints:

$query->where(function ($query) use ($dates) {
   foreach ($dates as $date) {
       $query->orWhereJsonContains('column', ['starts_at' => $date]);
   }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.