{"id":20238757,"url":"https://github.com/dwightwatson/aggregate","last_synced_at":"2025-10-11T00:36:45.076Z","repository":{"id":62546736,"uuid":"149070777","full_name":"dwightwatson/aggregate","owner":"dwightwatson","description":"Support additional aggregate queries on Eloquent relations","archived":false,"fork":false,"pushed_at":"2025-03-17T03:20:11.000Z","size":16,"stargazers_count":63,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-22T23:22:28.776Z","etag":null,"topics":["eloquent","laravel","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwightwatson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-17T04:56:12.000Z","updated_at":"2025-03-03T17:06:42.000Z","dependencies_parsed_at":"2024-06-18T18:20:49.922Z","dependency_job_id":"0b4c7c7b-2709-41ce-9019-8b5ab3a358ce","html_url":"https://github.com/dwightwatson/aggregate","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/dwightwatson/aggregate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwightwatson%2Faggregate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwightwatson%2Faggregate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwightwatson%2Faggregate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwightwatson%2Faggregate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwightwatson","download_url":"https://codeload.github.com/dwightwatson/aggregate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwightwatson%2Faggregate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005647,"owners_count":26083942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","php"],"created_at":"2024-11-14T08:35:36.950Z","updated_at":"2025-10-11T00:36:45.060Z","avatar_url":"https://github.com/dwightwatson.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Aggregate\n\nLaravel Eloquent allows you to query the count of a relationship using `withCount`. Aggregate extends Eloquent by adding `withSum`, `withAvg`, `withMin` and `withMax`.\n\nThis is based off the work in [`laravel/framework#25319`](https://github.com/laravel/framework/pull/25319) - thanks to Mohammad Sharif Ahrari ([@spyp](https://github.com/spyp)).\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require watson/aggregate\n```\n\n## Usage\n\nThe additional methods will be added by Laravel's autodiscovery feature. You can then use them the same way you already use `withCount`. [See the Laravel documentation for more on how this works](https://laravel.com/docs/5.7/eloquent-relationships#counting-related-models).\n\n```php\n$orders = Order::withSum('products', 'quantity')-\u003eget();\n\n$orders-\u003eeach(function ($order) {\n    $order-\u003eproducts_sum;\n});\n```\n\nYou can also select multiple aggregates in a single query, as well as alias them.\n\n```php\n$orders = Order::withCount('products')-\u003ewithSum('products as products_price', 'price')-\u003eget();\n\n$orders-\u003eeach(function ($order) {\n    $order-\u003eproducts_count;\n\n    $order-\u003eproducts_price;\n});\n```\n\n```php\n$orders = Order::withCount('products')-\u003ewithMax('products', 'price')-\u003eget();\n\n$orders-\u003eeach(function ($order) {\n    $order-\u003eproducts_count;\n\n    $order-\u003eproducts_max;\n});\n```\n\n### Testing\n\n``` bash\nvendor/bin/phpunit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwightwatson%2Faggregate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwightwatson%2Faggregate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwightwatson%2Faggregate/lists"}