From b83eaefa2ea89d8c8fef98416255971106fcb69b Mon Sep 17 00:00:00 2001 From: Fabian Wagner Date: Thu, 4 Dec 2025 11:34:19 +0100 Subject: [PATCH] A expiration scopes --- src/Traits/HasExpiration.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Traits/HasExpiration.php b/src/Traits/HasExpiration.php index 4420213..b24ac2c 100644 --- a/src/Traits/HasExpiration.php +++ b/src/Traits/HasExpiration.php @@ -50,4 +50,23 @@ trait HasExpiration ->orWhere('expires_at', '>', now()); }); } + + public function scopeWithExpired($query) + { + return $query->withoutGlobalScope('willExpire'); + } + + public function scopeExpiresWithinHours($query, int $hours) + { + return $query + ->withoutGlobalScope('willExpire') + ->whereBetween('expires_at', [now(), now()->addHours($hours)]); + } + + public function scopeExpiresFromTo($query, $from, $to) + { + return $query + ->withoutGlobalScope('willExpire') + ->whereBetween('expires_at', [$from, $to]); + } }