propaganistas/laravel-phone
Add Google libphonenumber-powered phone number validation and utilities to Laravel. Validate numbers by country (static list or matching a companion country field), cast attributes, format and compare numbers, and access phone metadata using a simple PhoneNumber class.
Pros:
Cons:
+1 (XXX) XXX-XXXX), though formatting methods can be extended.phone: rules (e.g., ['phone' => 'phone:US,BE|mobile']).phone_country columns).RawPhoneNumberCast/E164PhoneNumberCast.| Risk Area | Severity | Mitigation |
|---|---|---|
| Performance | Low | Lightweight (~1MB footprint); caching PhoneNumber objects can optimize repeated operations. |
| Backward Compatibility | Medium | Breaking changes in v6.x (enum migration) are minor; upgrade path documented. |
| Database Bloat | Medium | Search variants add columns; evaluate trade-offs (e.g., full-text search vs. partial matches). |
| Internationalization | High | Country-specific rules (e.g., +44 vs. 0 prefixes) must be tested rigorously. |
| Third-Party Dependencies | Low | Only giggsey/libphonenumber-for-php-lite; no external APIs by default. |
123 for testing) or strict (e.g., reject invalid formats)?PhoneNumber instantiation.regex/string rules with declarative phone: syntax (e.g., ['phone' => 'phone:INTERNATIONAL|mobile']).RawPhoneNumberCast/E164PhoneNumberCast integrate natively with model attributes.laravel-phone JS library).mbstring for Unicode handling (common in Laravel stacks).intl dependency (unlike libphonenumber Java/Python versions).| Phase | Tasks | Effort | Dependencies |
|---|---|---|---|
| Validation | Replace custom phone validation with phone: rules. |
Low | None |
| Database Schema | Add phone_country columns; migrate existing data to E.164 or raw storage. |
Medium | Laravel Migrations |
| Model Casting | Update Eloquent models to use RawPhoneNumberCast/E164PhoneNumberCast. |
Low | None |
| Utility Methods | Replace manual parsing (e.g., preg_replace) with PhoneNumber class methods. |
Medium | None |
| Search Optimization | Add search variants (normalized/national/E.164) via observers or model events. | High | Database Indexes |
| Testing | Validate edge cases (e.g., +44 020 7946 0958 vs. 02079460958), regional formats. |
High | Test Suite |
^6.0 for latest features.giggsey/libphonenumber-for-php-lite (v9.x in v6.x).laravel-telephone).+86 for China, +91 for India).formatAsMasked()).PhoneNumber instantiation time).libphonenumber-for-php-lite may introduce breaking changes (e.g., enum shifts in v9.0).composer.json (e.g., ^6.0) to avoid surprises.phone:!mobile).PhoneNumberType::UNKNOWN for invalid numbers → Use lenient() or stricter validation.US, not USA).phone_country before phone in model assignment.phone('+123', 'US')->getType() → Inspect number metadata.PhoneNumber::isValid() → Validate inputs early.How can I help you explore Laravel packages today?