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

Deekshith's avatar

multiple condition in same query

i have a requirement where it requires multiple where conditions in single query and i want to pass each condition to each variable to display the stats.

i have a table like below,

nominations table

id, user_id, status, file_name

now i want to get accepted, pending, rejected nominations. in single query so i tried query like below,

$nominations = Nomination::where('submited',1);
$approvedNominations = $nominations->where('status', 'Approved')->count();
 $pendingNominations = $nominations->where('status', 'Pending')->count();
 $rejectedNominations = $nominations->where('status', 'Rejected')->count();

but above code not showing proper count instead it s showing previous variable count in next variable.

please help me with this

0 likes
2 replies
AungHtetPaing__'s avatar
Level 22

@deekshith use get() to finish first query.

$nominations = Nomination::where('submited',1)->get();
$approvedNominations = $nominations->where('status', 'Approved')->count();
 $pendingNominations = $nominations->where('status', 'Pending')->count();
 $rejectedNominations = $nominations->where('status', 'Rejected')->count();
1 like

Please or to participate in this conversation.