Code Monkey home page Code Monkey logo

aggregate's Introduction

Aggregate

Laravel Eloquent allows you to query the count of a relationship using withCount. Aggregate extends Eloquent by adding withSum, withAvg, withMin and withMax.

This is based off the work in laravel/framework#25319 - thanks to Mohammad Sharif Ahrari (@spyp).

Installation

You can install the package via Composer:

composer require watson/aggregate

Usage

The 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.

$orders = Order::withSum('products', 'quantity')->get();

$orders->each(function ($order) {
    $order->products_sum;
});

You can also select multiple aggregates in a single query, as well as alias them.

$orders = Order::withCount('products')->withSum('products as products_price', 'price')->get();

$orders->each(function ($order) {
    $order->products_count;

    $order->products_price;
});
$orders = Order::withCount('products')->withMax('products', 'price')->get();

$orders->each(function ($order) {
    $order->products_count;

    $order->products_max;
});

Testing

vendor/bin/phpunit

aggregate's People

Contributors

dwightwatson avatar laravel-shift avatar spyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aggregate's Issues

Support for PHP 8

PHP 8 has been released but I can't use this package due to requirements in the package not accepting my PHP version.

Change package name if its possible

Thanks to develop this i started something like this but its better if we develop your package
I suggest. if you can change the package name . because we can wrapper model features that doesn't in laravel core. if no we have to create many packages for each feature :)

Support Laravel 9

Any plans on supporting Laravel 9? It seems the Illuminate/Database dependency is locked on 8.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.