Skip to content

Commit

Permalink
Fix undefined array key 'data' exception when trends are empty
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
eliseekn committed Sep 4, 2023
1 parent 90c2658 commit b296a64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `laravel-metrics` will be documented in this file

## 2.4.1

- Fix undefined array key 'data' exception when trends are empty
- Update README.md

## 2.4.0

- Add HasMetrics trait for models
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ LaravelMetrics::query(
->between('2020-05-01', '2022-08-21')
->trends();

// generate total count of the orders for the current year
// by using a custom label column
LaravelMetrics::query(Order::query())
->count()
->byMonth(12)
->labelColumn('status')
->trends();

// generate total count of the orders for the current year
// by using a custom label column
LaravelMetrics::query(Order::query())
Expand All @@ -108,7 +100,7 @@ $period = 'day', 'week', 'month' or 'year'
```

#### Notes
Periods are typically defined for the current month and/or year. However, you also have the option to define a specific month or year using dedicated methods. For example:
Periods are typically defined for the current day, week, month or year. However, you can define a specific value using dedicated methods. For example:
```php
// generate total count of the orders for the year 2023
//// by using a custom label column
Expand Down
5 changes: 4 additions & 1 deletion src/LaravelMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ public function trends(): array
? $this->formatDate($this->trendsData()->toArray())
: $this->trendsData()->toArray();

$result = [];
$result = [
'labels' => [],
'data' => []
];

foreach ($trendsData as $data) {
$result['labels'][] = $data->label;
Expand Down

0 comments on commit b296a64

Please sign in to comment.