'boolean', 'attempted_at' => 'datetime', ]; /** * Record a login attempt */ public static function recordAttempt( string $ipAddress, ?string $email = null, bool $successful = false, ?string $userAgent = null, ?string $country = null, ?string $notes = null ): self { return static::create([ 'ip_address' => $ipAddress, 'email' => $email, 'successful' => $successful, 'user_agent' => $userAgent, 'country' => $country, 'notes' => $notes, 'attempted_at' => now(), ]); } /** * Get recent failed attempts for an IP */ public static function getRecentFailedAttempts(string $ipAddress, int $minutes = 60): int { return static::where('ip_address', $ipAddress) ->where('successful', false) ->where('attempted_at', '>', now()->subMinutes($minutes)) ->count(); } /** * Get recent failed attempts for an email */ public static function getRecentFailedAttemptsForEmail(string $email, int $minutes = 60): int { return static::where('email', $email) ->where('successful', false) ->where('attempted_at', '>', now()->subMinutes($minutes)) ->count(); } }