-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Added PhoneNumber
for a cast model and validation rule, digging deeper
#54292
[11.x] Added PhoneNumber
for a cast model and validation rule, digging deeper
#54292
Conversation
… number functionality
Phone
for a cast model and validation rule, digging deeperPhoneNumber
for a cast model and validation rule, digging deeper
TODO: I encountered an issue with the test |
I really feel like this should be a package. 🙂 |
Hello @taylorotwell, Thank you for your feedback! 😊 While I understand the suggestion to make this a standalone package, integrating PhoneNumber directly into the framework adds significant value, similar to email validation. Phone numbers are a core part of many applications, and having built-in support for formatting, validation, and type-checking ensures developers can use this functionality without additional dependencies. It simplifies the developer experience and aligns with Laravel's philosophy of providing tools for common application needs out of the box. Feel free to let me know if you have further thoughts! 🙌 |
This pull request introduces the PhoneNumber class to handle phone number operations in a standardized and extensible manner. Additionally, the PR includes enhancements to integrate the PhoneNumber class within Laravel models through casting and validation rules. I think the community needs this in framework like email.
Key Features
Provides a clean API for handling phone number formatting, validation, and type checking.
Supports multiple formats: International, National, E164, and RFC3966.
Integrates with the
libphonenumber
library for accurate phone number parsing and formatting.Model Casting:
Introduced a custom cast to seamlessly handle PhoneNumber objects in Laravel models.
Validation Rule:
Added a custom validation rule ValidPhoneNumber to ensure phone numbers conform to the expected format and are valid for the given region.
Digging Deeper PhoneNumber:
Added a custom class for Digging Deeper to ensure phone numbers conform to the expected format and are valid for the given region.
Enhancements:
Unit Tests: Comprehensive test coverage for the PhoneNumber class, model casting, and validation rule.
Error Handling: Improved exception handling for invalid numbers and unsupported operations.
Notes:
This implementation leverages the
libphonenumber
library for core phone number operations, ensuring reliability and accuracy.The validation rule supports regional validation, making it adaptable to different use cases.
Let me know if further refinements or additional features are needed!