From ab6d2f29d27e7ca26b790864f8b249fe044d9b04 Mon Sep 17 00:00:00 2001 From: Fabian Wagner Date: Tue, 25 Nov 2025 10:48:09 +0100 Subject: [PATCH] I expirations --- src/Traits/HasExpiration.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Traits/HasExpiration.php b/src/Traits/HasExpiration.php index c1475fd..4420213 100644 --- a/src/Traits/HasExpiration.php +++ b/src/Traits/HasExpiration.php @@ -32,4 +32,22 @@ trait HasExpiration $this->save(); } + + public function scopeExpired($query) + { + return $query + ->withoutGlobalScope('willExpire') + ->whereNotNull('expires_at') + ->where('expires_at', '<=', now()); + } + + public function scopeWillExpire($query) + { + return $query + ->withoutGlobalScope('willExpire') + ->where(function ($query) { + $query->whereNull('expires_at') + ->orWhere('expires_at', '>', now()); + }); + } }