承接 filippo-toso/eloquent-aggregates 相关项目开发

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

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

filippo-toso/eloquent-aggregates

Composer 安装命令:

composer require filippo-toso/eloquent-aggregates

包简介

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

README 文档

README

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

Requirements

  • PHP 7.2+
  • Laravel 5.7+

Installing

Use Composer to install it:

composer require filippo-toso/eloquent-aggregates

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?

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

统计信息

  • 总下载量: 290
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固