From 3ba37d78a9b6911ebefcc7520bfff36fb799ee16 Mon Sep 17 00:00:00 2001 From: Thomas Verstraete Date: Sat, 28 Dec 2024 13:10:54 -0500 Subject: [PATCH] Update README.md to document dateAlias method --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index a31aa9c..e8f7232 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,23 @@ Trend::model(Order::class) This allows you to work with models that have custom date column names or when you want to analyze data based on a different date column. +## Date Column Alias + +By default, laravel-trend creates a grouping select field in its database query named `date`. This can cause problems if you have a column on that table already named `date`. To avoid this conflict in the query specify a different name with `dateAlias(string $alias)` method. + +Example: + +```php +Trend::model(Order::class) + ->dateColumn('date') + ->dateAlias('date_alias') + ->between(...) + ->perDay() + ->count(); +``` + +This allows you to work with models that have a column named `date`. + ## Drivers We currently support four drivers: