Skip to main content
Back to packages
3,012 GitHub stars

Propaganistas/Laravel-Phone

View on GitHub

Description

Adds phone number functionality to Laravel based on the PHP port of Google\s libphonenumber API by giggsey.

Use the phone keyword in your validation rules array or use the Propaganistas\LaravelPhone\Rules\Phone rule class to define the rule in an expressive way.

To put constraints on the allowed originating countries, you can explicitly specify the allowed country codes.

'my_input' => 'phone:US,BE',
// 'my_input' => (new Phone)->country(['US', 'BE'])

Or to make things more dynamic, you can also match against another data field holding a country code. For example, to require a phone number to match the provided country of residence. Make sure the country field has the same name as the phone field but with _country appended for automatic discovery, or provide your custom country field name as a parameter to the validator:

'my_input' => 'phone',
// 'my_input' => (new Phone)
'my_input_country' => 'required_with:my_input',
'my_input' => 'phone:custom_country_field',
// 'my_input' => (new Phone)->countryField('custom_country_field')
'custom_country_field' => 'required_with:my_input',

Recent Courses on Laravel Daily

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.