Could we help you? Please click the banners. We are young and desperately need the money
Let's say that we have a table column called json_data and it contains following values in first two rows:
[
{
"data": {
"id": "1"
},
"name": "some-id"
},
{
"data": {
"test-status": "ok"
},
"other-name": "test"
}
]
[
{
"data": {
"id": "2"
},
"name": "some-other-id"
},
{
"data": {
"test-status": "ok"
},
"name": "other-test"
},
{
"random": {
"random-key": 2
}
}
]
If we want to find all results where data key contains an array with a key test-status and it's value is equal to ok then we need to write a query like this:
Model::whereJsonContains('json_data', ['data' => ['test-status' => 'ok']])->get();