Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Phone

Laravel Phone Laravel Package

propaganistas/laravel-phone

Add robust phone number validation, casting, and formatting to Laravel using Google’s libphonenumber (PHP port). Validate by country or dynamic country fields, cast model attributes to phone objects, format numbers consistently, and compare/evaluate phone metadata.

View on GitHub
Deep Wiki
Context7

Adds phone number functionality to Laravel based on Google's libphonenumber API.

Frequently asked questions about Laravel Phone
How do I install and set up Laravel Phone in my Laravel project?
Run `composer require propaganistas/laravel-phone` to install. The package auto-discovers its service provider. Add a `'phone' => 'The :attribute field must be a valid number.'` translation entry to your `validation.php` language files for validation messages.
What Laravel versions does this package support?
The package supports Laravel 8.x, 9.x, and 10.x. Check the [Packagist page](https://packagist.org/packages/propaganistas/laravel-phone) for the latest version compatibility details.
Can I validate phone numbers by country? How?
Yes. Use `phone:US,BE` in your validation rules to restrict numbers to specific countries (e.g., US and Belgium). For dynamic country matching, use `phone:country_field` where `country_field` holds the country code, or pass a custom field name to the validator.
What are the Eloquent cast types for phone numbers, and how do I use them?
The package provides two casts: `RawPhoneNumberCast` (stores raw input) and `E164PhoneNumberCast` (stores E.164 format). Use them in your model like `$casts = ['phone' => E164PhoneNumberCast::class]` to automatically parse and validate phone numbers.
How should I store phone numbers in the database for optimal search and validation?
Store numbers in E.164 format (e.g., `+1234567890`) for consistency. For search flexibility, consider adding columns for national format (e.g., `020 1234 5678`) and raw input. The package doesn’t include migrations, so you’ll need to create these columns manually.
Does this package handle SMS or voice API integrations like Twilio?
No. Laravel Phone focuses solely on parsing, validation, and storage. For SMS/voice services, you’ll need to integrate third-party APIs like Twilio, AWS SNS, or Plivo separately.
How do I format phone numbers for display (e.g., international vs. national format)?
Use the `PhoneNumber` utility class. Call `PhoneNumber::format($number, 'INTERNATIONAL')` or `PhoneNumber::format($number, 'NATIONAL')` to get formatted strings. You can also specify a country code for regional formatting.
What’s the best way to handle high-volume phone number validation (e.g., 10,000+ numbers/hour)?
The underlying `libphonenumber` is CPU-intensive. For bulk validation, cache results using Redis or implement async processing (e.g., queues). Test performance under load before deploying to production.
Can I compare two phone numbers for equality, even if formatted differently?
Yes. Use `PhoneNumber::equals($number1, $number2)` to compare numbers regardless of formatting. This method normalizes inputs to E.164 format before comparison.
Are there alternatives to this package for phone validation in Laravel?
Alternatives include `egulias/email-validator` (for combined email/phone validation), `respect/validation` with custom phone rules, or standalone libraries like `monolog/monolog` (though not phone-specific). Laravel Phone stands out for its deep Google libphonenumber integration and Laravel-specific features like Eloquent casts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai