Skip to content

Commit 7e5c06b

Browse files
committed
closes #5 - support for individual created_at column names per model
1 parent 1400669 commit 7e5c06b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ return [
6363
'default_range' => env('DATE_SCOPES_DEFAULT_RANGE', DateRange::EXCLUSIVE->value),
6464

6565
/**
66-
* If you have a custom created_at column name, change it here.
66+
* If you use a global custom created_at column name, change it here.
6767
*/
6868
'created_column' => env('DATE_SCOPES_CREATED_COLUMN', 'created_at'),
6969
];

src/DateScopes.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ public function scopeOfLastUnit(Builder $query, string $dateUnit, int $value, Da
135135
// if (defined('DATE_SCOPE_DEBUG'))
136136
// dd(collect($range)->transform(fn ($item) => $item->format('Y-m-d H:i:s'))->toArray());
137137

138-
return $query->whereBetween(config('date-scopes.created_column'), $range);
138+
$createdColumnName = (self::CREATED_AT != 'created_at') ? self::CREATED_AT : config('date-scopes.created_column');
139+
140+
return $query->whereBetween($createdColumnName, $range);
139141
}
140142

141143
// START SECONDS

0 commit comments

Comments
 (0)