问题
I have an array of JSON objects within my database (as depicted by the image below)
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?
回答1:
Use this:
->whereJsonContains('column', ['starts_at' => '2018-11-24 08:00:00'])
来源:https://stackoverflow.com/questions/53007520/laravel-eloquent-working-with-an-array-of-json-objects