php - 从 MySql 数据库中的 JSON 列获取数据
问题描述
在我的表中有一个包含JSON
编码数据的列,一个记录看起来像这样
{"late_fee":10,
"due_date":"2019-10-01 00:00:00",
"property_type":"house"
}
从数据库获取数据时,我需要数据列late_fee
中不存在键的记录。JSON
我怎样才能把它放在where
状态?
这是我必须添加上述条件的代码行:
$payments = Rent::where('property_id', $property['id']);`
编辑
通过您发布的评论,您能否向我确认这是正确的方法:
$payments = Rent::where('property_id', $property['id'])->whereJsonContains('notification_settings->late_fee', null);
PS是存储数据notification_settings
的列的名称。JSON
解决方案
只需阅读这篇短文: https ://laravel.com/docs/5.7/queries#json-where-clauses
那应该工作:
$payments = Rent::where('property_id', $property['id'])->whereJsonContains('notification_settings->late_fee', null);
推荐阅读
- reactjs - 反应本机导航 2
- python - Numpy 删除重复的列值
- vba - Excel VBA-使用VBIDE.CodeModule创建动态变量名关闭用户窗体不会重新加载?
- typescript - TSLint 中的 `extends` 和 `rulesDirectory` 有什么区别
- feathersjs - FeathersJS:后处理服务
- python - 无法将 netCDF 数据加载到 python 中
- javascript - 如何使用滑块和调整大小属性调整图像大小
- javascript - 在滚动事件上反应更改图像源
- regex - 正则表达式拆分csv,用引号括起来的值,值有引号
- python - 我的 while 函数无法正常工作 PYTHON,我不知道出了什么问题