From 7e5c06b7c4e1c5661433d230be0835a17ac05b3a Mon Sep 17 00:00:00 2001 From: Sairahcaz Date: Tue, 2 May 2023 22:34:24 +0200 Subject: [PATCH] closes #5 - support for individual created_at column names per model --- README.md | 2 +- src/DateScopes.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dfe4bd5..8589cf3 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ return [ 'default_range' => env('DATE_SCOPES_DEFAULT_RANGE', DateRange::EXCLUSIVE->value), /** - * If you have a custom created_at column name, change it here. + * If you use a global custom created_at column name, change it here. */ 'created_column' => env('DATE_SCOPES_CREATED_COLUMN', 'created_at'), ]; diff --git a/src/DateScopes.php b/src/DateScopes.php index a268a80..5acfebd 100755 --- a/src/DateScopes.php +++ b/src/DateScopes.php @@ -135,7 +135,9 @@ public function scopeOfLastUnit(Builder $query, string $dateUnit, int $value, Da // if (defined('DATE_SCOPE_DEBUG')) // dd(collect($range)->transform(fn ($item) => $item->format('Y-m-d H:i:s'))->toArray()); - return $query->whereBetween(config('date-scopes.created_column'), $range); + $createdColumnName = (self::CREATED_AT != 'created_at') ? self::CREATED_AT : config('date-scopes.created_column'); + + return $query->whereBetween($createdColumnName, $range); } // START SECONDS