Support the ongoing development of Laravel.io →
posted 6 years ago
Eloquent
Last updated 1 year ago.
0
Solution

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.

0

No problem.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

cotherman cotherman Joined 25 Apr 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.