In Laravel, you can use the count()
method to count the total number of results in a collection. The count()
method returns the total number of items in the collection.
Here is an example of how to use the count()
method to count the total number of results in a collection:
$collection = collect([1, 2, 3, 4, 5]);
$total = $collection->count(); // 5
You can also use the size()
method, which is an alias for the count()
method, to achieve the same result:
$collection = collect([1, 2, 3, 4, 5]);
$total = $collection->size(); // 5