Level 29
I assumed the column name is seller_id
By referring to https://laravel.com/docs/7.x/eloquent#retrieving-models=
Single Model
$orders->where('seller_id',$id)->latest()->first();
or
$orders->whereSellerId($id)->latest()->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
it not working.
$orders = new Order;
if($id) {
$orders->whereSeller_id($id);
}
$orders->latest()->get();
dd($orders);
@mahaveer Use Conditional Clauses
$orders = Order::when($id, function ($query, $id) {
return $query->where('seller_id', $id);
})->latest()->get();
Docs: https://laravel.com/docs/7.x/queries#conditional-clauses
Please or to participate in this conversation.