darsyn/ip
Laravel package for working with IP addresses: parse and validate IPv4/IPv6, compare and normalize formats, check ranges and subnet/CIDR matches, and convert between representations. Useful for request filtering, geo/security rules, and logging.
IpAddress value objects).IpAddress objects).Ip::fromString($ip)->isPrivate()).Ip::fromRequest()), reducing custom glue code.Request object must handle ip() correctly in dual-stack environments).IpAddress objects in unit tests, or rely on the package’s built-in assertions?app/Http/Middleware/ValidateIp.php).request()->ip() with Ip::fromRequest()->isTrusted().Illuminate\Queue\Events\JobProcessed for audit logs.IpAddress objects in:
Ip::fromRequest()).IpAddress column → Ip::fromString($ip)).IpValidator) to reject invalid IPs early.IpAddress objects in responses (e.g., JsonResource).Ip::isInRange($ip, '192.168.0.0/16')).filter_var (for IPv6) is available.IpAddress objects (serialize with json_encode() if needed).InvalidIpAddressException) for clear error messages.Ip::fromRequest()->toString()) for auditing.Ip::fromString() results) if parsing is a bottleneck.IpAddress objects in APIs).| Failure Scenario | Mitigation |
|---|---|
| Malformed IP input | Use try-catch with InvalidIpAddressException or fallback to filter_var. |
| IPv6 misconfiguration | Test with ::1 (localhost IPv6) and real IPv6 addresses. |
| CIDR range errors | Validate ranges at startup (e.g., Ip::isValidCidr('192.168.0.0/33')). |
| Package compatibility breaks | Pin version in composer.json during migration. |
IpAddress over strings (e.g., linting rules).Ip::fromRequest() in middleware").isPrivate(), isInRange()).How can I help you explore Laravel packages today?