PHP code example of watson / aggregate

1. Go to this page and download the library: Download watson/aggregate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

watson / aggregate example snippets


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

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

$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;
});