Skip to content

Commit

Permalink
closes #5 - support for individual created_at column names per model
Browse files Browse the repository at this point in the history
  • Loading branch information
Sairahcaz committed May 2, 2023
1 parent 1400669 commit 7e5c06b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
Expand Down
4 changes: 3 additions & 1 deletion src/DateScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e5c06b

Please sign in to comment.