How to Use Aggregate Functions With Laravel Eloquent?

Aggregate functions are available in same way in Laravel eloquent as they were with Laravel query builder. Here is an example of count() method.

$countVips = Contact::where( 'vip', true )->count();

We can also use sum functions.

$sumVotes = Contact::sum('votes');

Another method is average which is used as avg().

$avgSkills = Contact::avg( 'skill_level' );

That is all for aggregate methods. If you have any question please leave a comment. We really appreciate that.