Because you just asked the collection for the last item, then you called count on that ... Calling count on a model instance runs a count query on the table. As there is nothing to count on a model instance itself. The count call gets passed to the builder.
$a = App\SomeModel::where('id', 1)->get();
Is a collection.
$a = $a->last();
Asking the collection for the last item.
$a->count();
calling count on a model instance, causes a count query on the table.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.