[英]Get data from JSON column in MySql database
在我的表格中,有一列包含JSON
编码的数据,一条记录如下所示
{"late_fee":10,
"due_date":"2019-10-01 00:00:00",
"property_type":"house"
}
当从数据库中获取数据时,我需要在JSON
数据列中不存在键late_fee
记录。 如何将其放在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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.