Laravel Eloquent - 使用 JSON 对象数组 [英] Laravel Eloquent - Working with an array of JSON objects
本文介绍了Laravel Eloquent - 使用 JSON 对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有一组 JSON 对象(如下图所示)
I have an array of JSON objects within my database (as depicted by the image below)
如何在其中搜索特定值?假设我想要ends_at"字段等于2018-11-24 08:00:00"的记录
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"
我试过使用
->where('column->starts_at', '2018-11-24 08:00:00')
甚至尝试过
->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?
推荐答案
使用这个:
->whereJsonContains('column', ['starts_at' => '2018-11-24 08:00:00'])
这篇关于Laravel Eloquent - 使用 JSON 对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文