Weave 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

Laravel Phone adds phone number functionality to Laravel via libphonenumber. Validate numbers with country constraints, cast attributes, format and compare numbers, and handle international input with ease. Ideal for forms, APIs, and user profiles.

View on GitHub
Deep Wiki
Context7

Laravel Phone adds robust phone number handling to Laravel, powered by Google's libphonenumber through its PHP port. With an auto-discovered service provider and a single translation entry, you can validate, format, and inspect international numbers with minimal setup.

  • Validation rules — use the phone keyword or the expressive Phone rule class, with explicit country constraints or dynamic matching against a country field.
  • Formatting — render numbers in international, national, or E.164 formats.
  • Number information — detect country, number type, and validity.
  • Equality comparison — compare numbers regardless of formatting.
  • Attribute casting — cast model attributes to phone number objects automatically.
Frequently asked questions about Laravel Phone
How do I install and set up Laravel-Phone in a Laravel 13 project?
Run `composer require propaganistas/laravel-phone`, then add the validation rule translation to your language files (e.g., `validation.php`). The package auto-discovers the service provider, so no manual registration is needed. Test with a simple rule like `phone:US` in your validation logic.
What Laravel versions does this package support?
Laravel-Phone is fully compatible with Laravel 10+, including Laravel 13. It requires PHP 8.1+ due to dependencies like `libphonenumber-for-php-lite`. Always check the latest release notes for version-specific updates.
Can I validate phone numbers by country or type (e.g., mobile, landline)?
Yes. Use country codes like `phone:US,BE` for specific countries or add types like `phone:US,mobile`. For dynamic validation, pair phone fields with country fields (e.g., `user_phone` and `user_country`) using the `_country` suffix convention.
How should I store phone numbers in the database—raw input or E.164 format?
Store E.164 format for uniqueness and consistency (e.g., `+14155552671`). If you need raw input for user editing, store both `phone_raw` and `phone_country` columns, then derive E.164 via the `PhoneNumber` utility class. This balances validation and user experience.
Does this package work with Eloquent model casting? How do I cast a phone field?
Yes. Use `E164PhoneNumberCast` for normalized storage or `RawPhoneNumberCast` if you need raw input. Add the cast to your model’s `$casts` array, e.g., `protected $casts = ['phone' => E164PhoneNumberCast::class];`. The package handles conversion automatically.
What’s the performance impact of phone validation in bulk operations?
Validation is lightweight for most cases, but heavy operations (e.g., LENIENT mode) may slow bulk inserts. Benchmark your workflows. For high-throughput apps, consider caching validated numbers or deferring validation until necessary.
How do I format phone numbers for display or dialing in Blade templates?
Use the `PhoneNumber` utility class methods like `$user->phone->formatNational()` for display or `$user->phone->formatForMobileDialingInCountry('US')` for clickable links. Example: `<a href="tel:{{ $user->phone->formatE164() }}">{{ $user->phone->formatInternational() }}</a>`.
Are there alternatives to this package? Why choose Laravel-Phone?
Alternatives include direct use of `giggsey/libphonenumber-for-php`, but Laravel-Phone provides Laravel-specific integrations (validation rules, Eloquent casts, Blade helpers) and a cleaner API. It’s actively maintained and designed for Laravel’s ecosystem.
How do I handle invalid phone numbers in validation errors?
Invalid numbers trigger Laravel’s default validation errors. Customize error messages in your language files (e.g., `'phone' => 'The :attribute must be a valid number.'`). For logging, extend the `Phone` rule class or use Laravel’s `failed` event listeners.
Can I dynamically detect a user’s country for phone validation?
Yes. Use the `_country` suffix convention (e.g., `user_phone` and `user_country`) or manually pass a country field to the validator. Example: `'phone' => ['phone', 'country_field:user_country']`. This enables context-aware validation.
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.
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai