Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Austinbryan's avatar

My query returning unexpected result

I’m using this eloquent query in a table in my database with an array of values,

Sumalr::where(‘type’, 1)
->where(function ($q) use ($query) {
    $q->whereIn('nwlo', $query);
    $q->orWhereIn('walo', $query);
})
->whereNull('wedr_id')
->orderBy('id', 'asc')
->get();
 

query variable is an array of 2 values ['WEE', 'EGGT'] in my Sumalr table I have 1 row that has a public value of 1, a departure value of EGGT, and the wedr_id is null yet that does not get returned.

0 likes
2 replies
a4ashraf's avatar
a4ashraf
Best Answer
Level 33

@austinbryan

you DB field is JSON formated

Try with This

Sumalr::where(type, 1)
$data = ['WEE', 'EGGT'] 
->where(function ($query) use ($data) {
    foreach ($data as $apt) {
        $query->whereJsonContains('EGGT', $apt);
        $query->orWhereJsonContains('WEE', $apt);
    }
})
->whereNull(‘wefr_id’)
->orderBy('id', 'asc')
->get();

``
1 like

Please or to participate in this conversation.