I use laravel 5.6
I have a field. The data type of the field is json
The value of the field (desc field) like this :
[
{"code": "1", "club": "CHE", "country": "ENGLAND"},
{"code": "2", "club": "BAY", "country": "GERMANY"},
{"code": "3", "club": "JUV", "country": "ITALY"},
{"code": "4", "club": "RMA", "country": "SPAIN"},
{"code": "5", "club": "CHE", "country": "ENGLAND"},
{"code": "6", "club": "BAY", "country": "GERMANY"},
{"code": "7", "club": "JUV", "country": "ITALY"},
{"code": "8", "club": "RMA", "country": "SPAIN"},
{"code": "CODE", "club": "CLUB", "country": "COUNTRY"}
]
I want to check the key of club have value "CHE" or not
I try like this :
->where('desc->club','=', 'CHE')->get();
But it does not work
How can I solve this problem?
Just use a SQL LIKE
operator
->where('desc', 'like', '%"club": "CHE"%');
Try this:
->whereRaw('JSON_CONTAINS(`desc`, \'{"club":"CHE"}\')')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With