File tree Expand file tree Collapse file tree 1 file changed +9
-26
lines changed Expand file tree Collapse file tree 1 file changed +9
-26
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,16 @@ public static function boot()
59
59
static ::created (function ($ verificationCode ) {
60
60
$ maxCodes = config ('verification-code.max_per_verifiable ' , 1 );
61
61
62
- if ($ maxCodes ! == null ) {
63
- VerificationCode:: exceptRecentFor ( $ verificationCode -> verifiable , $ maxCodes )-> delete () ;
62
+ if ($ maxCodes = == null ) {
63
+ return ;
64
64
}
65
+
66
+ VerificationCode::for ($ verificationCode ->verifiable )
67
+ ->orderByDesc ('expires_at ' )
68
+ ->orderByDesc ('id ' )
69
+ ->skip ($ maxCodes )
70
+ ->take (PHP_INT_MAX )
71
+ ->delete ();
65
72
});
66
73
}
67
74
@@ -104,28 +111,4 @@ public function scopeFor($query, string $verifiable)
104
111
{
105
112
return $ query ->where ('verifiable ' , $ verifiable );
106
113
}
107
-
108
- /**
109
- * Scope a query to only include verification codes from the provided verifiable.
110
- *
111
- * @param \Illuminate\Database\Eloquent\Builder $query
112
- * @param string $verifiable
113
- * @param int $amount
114
- *
115
- * @return \Illuminate\Database\Eloquent\Builder
116
- */
117
- public function scopeExceptRecentFor ($ query , string $ verifiable , int $ amount )
118
- {
119
- return $ query
120
- ->for ($ verifiable )
121
- ->whereNotIn (
122
- 'id ' ,
123
- static ::query ()
124
- ->select ('id ' )
125
- ->for ($ verifiable )
126
- ->orderByDesc ('expires_at ' )
127
- ->orderByDesc ('id ' )
128
- ->limit ($ amount )
129
- );
130
- }
131
114
}
You can’t perform that action at this time.
0 commit comments