PASSWORD RESET

Your destination for complete Tech news

How to count total results in a collection in Laravel?

253 0
< 1 min read

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

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.