Tom Hemus
Tom Hemus

Reputation: 125

Laravel Eloquent - Working with an array of JSON objects

I have an array of JSON objects within my database (as depicted by the image below)

enter image description here

How do I search for a specific value within it? Say I want the record where the "ends_at" field is equal to "2018-11-24 08:00:00"

I've tried using

->where('column->starts_at', '2018-11-24 08:00:00')

or even tried

->whereJsonContains('column->starts_at', '2018-11-24 08:00:00').

Within the model I've cast the column to an array - am I missing something, or can this not be done?

Upvotes: 2

Views: 3099

Answers (1)

Jonas Staudenmeir
Jonas Staudenmeir

Reputation: 25936

Use this:

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

Upvotes: 10

Related Questions