XetaIO /
Xetaravel
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Xetaravel\Models\Gates; |
||
| 6 | |||
| 7 | use Carbon\Carbon; |
||
| 8 | use Illuminate\Support\Facades\Auth; |
||
| 9 | |||
| 10 | trait FloodGate |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Check whatever the user is flooding or not. |
||
| 14 | * |
||
| 15 | * @param string $rule The configuration rule to use. |
||
| 16 | * |
||
| 17 | * @return bool |
||
| 18 | */ |
||
| 19 | public static function isFlooding(string $rule = 'xetaravel.flood.general'): bool |
||
| 20 | { |
||
| 21 | $class = get_called_class(); |
||
| 22 | $user = Auth::user(); |
||
| 23 | |||
| 24 | return $class::where('user_id', $user->id) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | ->where( |
||
| 26 | 'created_at', |
||
| 27 | '>=', |
||
| 28 | Carbon::now()->subSeconds(config($rule)) |
||
| 29 | ) |
||
| 30 | ->exists(); |
||
| 31 | } |
||
| 32 | } |
||
| 33 |