Laravel Eloquent - Working with an array of JSON objects

半世苍凉 提交于 2020-11-29 03:04:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!