Skip to content
Advertisement

laravel, How to check if this is the last record

how can I check if the current record is the last one in the model?

   $lastorder=Order::find($order_id);
    if($lastorder->last())

Advertisement

Answer

$orders = Order::where('id','>=', $order_id)->get();

$order = $orders->first();

if($orders->count() > 1) {
   //...
   // NOT the last record :(
   //...
} else { 
   //...
   // Last record :)
   //...
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement