承接 watson/aggregate 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

watson/aggregate

最新稳定版本:5.3.0

Composer 安装命令:

composer require watson/aggregate

包简介

Extend Laravel's query builder with additional relation aggregates.

README 文档

README

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

统计信息

  • 总下载量: 134.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 63
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 62
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-17