PHPackages                             filippo-toso/eloquent-aggregates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. filippo-toso/eloquent-aggregates

ActiveLibrary[Database &amp; ORM](/categories/database)

filippo-toso/eloquent-aggregates
================================

A simple trait to add support for aggregate functions in Eloquent models

v1.0.2(4y ago)0283MITPHPPHP ^7.0 || ^8.0 || ^9.0

Since Oct 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/filippotoso/eloquent-aggregates)[ Packagist](https://packagist.org/packages/filippo-toso/eloquent-aggregates)[ RSS](/packages/filippo-toso-eloquent-aggregates/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (5)Used By (0)

Eloquent Aggregates
===================

[](#eloquent-aggregates)

A simple trait to add support for aggregate functions in Eloquent models.

Requirements
------------

[](#requirements)

- PHP 7.2+
- Laravel 5.7+

Installing
----------

[](#installing)

Use Composer to install it:

```
composer require filippo-toso/eloquent-aggregates

```

How to use it
-------------

[](#how-to-use-it)

Add the `FilippoToso\Eloquent\Aggregates\Concerns\HasAggregates` trait to your models. Then you can use the following methods:

```
// Get the sum of all the amount fields in the transactions relationship
$users = App\Users::withSum('amount', 'transactions')->get();

// Get the max of all the amount fields in the transactions relationship
$users = App\Users::withMax('amount', 'transactions')->get();

// Get the min of all the amount fields in the transactions relationship
$users = App\Users::withMin('amount', 'transactions')->get();

// Get the average of all the amount fields in the transactions relationship
$users = App\Users::withAvg('amount', 'transactions')->get();

```

You can also add constraints to the relationship query:

```
$users = App\Users::withAvg('amount', ['transactions' => function ($query) {
    // Include only the transaction created in the last seven days
    $query->whereDate('created_at', '>=', Carbon\Carbon::today()->subDays(7));
}])->get();

```

Already extending the Eloquent Builder?
---------------------------------------

[](#already-extending-the-eloquent-builder)

If you are already extending the `Illuminate\Database\Eloquent\Builder`, just add the trait `FilippoToso\Eloquent\Aggregates\Concerns\QueriesAggregates` to your Builder class.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~240 days

Total

4

Last Release

1691d ago

Major Versions

v0.0.1 → v1.0.02019-10-06

PHP version history (2 changes)v0.0.1PHP ^7.2

v1.0.2PHP ^7.0 || ^8.0 || ^9.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/55d89f2d44fb12225de2119994028ee69e36770bcf33c2b1ddf0d6672d28151b?d=identicon)[filippo.toso](/maintainers/filippo.toso)

---

Top Contributors

[![filippotoso](https://avatars.githubusercontent.com/u/26958813?v=4)](https://github.com/filippotoso "filippotoso (4 commits)")

### Embed Badge

![Health badge](/badges/filippo-toso-eloquent-aggregates/health.svg)

```
[![Health](https://phpackages.com/badges/filippo-toso-eloquent-aggregates/health.svg)](https://phpackages.com/packages/filippo-toso-eloquent-aggregates)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[aglipanci/laravel-eloquent-case

Adds CASE statement support to Laravel Query Builder.

115157.2k](/packages/aglipanci-laravel-eloquent-case)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
