In my table there is a column with JSON
encoded data and one record looks something like this
{"late_fee":10,
"due_date":"2019-10-01 00:00:00",
"property_type":"house"
}
When getting data from database I need records where key late_fee
does not exist in JSON
data column. How can I put it in where
condition?
This is the line of code on which I have to add mentioned condition:
$payments = Rent::where('property_id', $property['id']);`
EDIT
By comments you posted, can you confirm me that this is the right way:
$payments = Rent::where('property_id', $property['id'])->whereJsonContains('notification_settings->late_fee', null);
PS notification_settings
is the name of column where JSON
data is stored.
Just read this short article: https://laravel.com/docs/5.7/queries#json-where-clauses
That should work :
$payments = Rent::where('property_id', $property['id'])->whereJsonContains('notification_settings->late_fee', null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.