From ffeb4200fa3e3030a09bd3cd678d56e82f766200 Mon Sep 17 00:00:00 2001 From: eliseekn Date: Sat, 26 Aug 2023 15:40:51 +0000 Subject: [PATCH] Add forDay and forMonth methods Change by and aggregate methods to protected --- CHANGELOG.md | 4 ++++ README.md | 19 ++++++++++++++++--- src/LaravelMetrics.php | 16 ++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d023278..d989bb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-metrics` will be documented in this file +## 2.3.0 + +- Add forDay and forMonth methods + ## 2.1.0 - Add custom label column definition diff --git a/README.md b/README.md index e4afc2b..1b1913c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LaravelMetrics +# Metrics for Laravel [![Latest Version on Packagist](https://img.shields.io/packagist/v/eliseekn/laravel-metrics.svg?style=flat-square)](https://packagist.org/packages/eliseekn/laravel-metrics) [![Total Downloads](https://img.shields.io/packagist/dt/eliseekn/laravel-metrics.svg?style=flat-square)](https://packagist.org/packages/eliseekn/laravel-metrics) @@ -98,7 +98,6 @@ LaravelMetrics::query(Order::query()) ->byMonth(int $count = 0) ->byYear(int $count = 0) ->between(string $startDate, string $endDate) -->by(string $period, int $count = 0) ``` ```php @@ -126,8 +125,23 @@ LaravelMetrics::query(Product::query()) ->byDay(1) ->forMonth(2) ->metrics(); + +// generate total sum of the orders amount for the month march only +LaravelMetrics::query(Product::query()) + ->sum('amount') + ->byMonth(1) + ->forMonth(3) + ->metrics(); ``` +```php +->forDay(int $day) +->forWeek(int $week) +->forMonth(int $month) +->forYear(int $year) +``` + + ### Types of aggregates ```php ->count(string $column = 'id') @@ -135,7 +149,6 @@ LaravelMetrics::query(Product::query()) ->sum(string $column) ->max(string $column) ->min(string $column) -->aggregate(string $aggregate, string $column) ``` ### Types of data diff --git a/src/LaravelMetrics.php b/src/LaravelMetrics.php index c40d6b9..b31ed77 100644 --- a/src/LaravelMetrics.php +++ b/src/LaravelMetrics.php @@ -52,7 +52,7 @@ public static function query(Builder $builder): self return new self($builder); } - public function by(string $period, int $count = 0): self + protected function by(string $period, int $count = 0): self { $period = strtolower($period); @@ -92,6 +92,18 @@ public function between(string $start, string $end): self return $this; } + public function forDay(int $day): self + { + $this->day = $day; + return $this; + } + + public function forWeek(int $week): self + { + $this->week = $week; + return $this; + } + public function forMonth(int $month): self { $this->month = $month; @@ -104,7 +116,7 @@ public function forYear(int $year): self return $this; } - public function aggregate(string $aggregate, string $column): self + protected function aggregate(string $aggregate, string $column): self { $aggregate = strtolower($aggregate);