Level 23
$id = 1;
$groups = DB::table('table_example');
if($id!='0') {
$groups->where('id', '=', $id)
}
$groups->limit(30)->get();
Try that.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I would like to put a condition in a query, but I do some things wrong, what is it?
$id = 1;
$groups = DB::table('table_example')
if($id!='0'){
->where('id', '=', $id)
}
->limit(30)
->get();
Best regards
$id = 1;
$groups = DB::table('table_example');
if($id!='0') {
$groups->where('id', '=', $id)
}
$groups->limit(30)->get();
Try that.
Please or to participate in this conversation.