Skip to content

Commit

Permalink
Add forDay and forMonth methods
Browse files Browse the repository at this point in the history
Change by and aggregate methods to protected
  • Loading branch information
eliseekn committed Aug 26, 2023
1 parent 4c7d5d2 commit ffeb420
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -126,16 +125,30 @@ 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')
->average(string $column)
->sum(string $column)
->max(string $column)
->min(string $column)
->aggregate(string $aggregate, string $column)
```

### Types of data
Expand Down
16 changes: 14 additions & 2 deletions src/LaravelMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit ffeb420

Please sign in to comment.