Skip to main content
Back to packages
3,021 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

Roles and Permissions in Laravel 13

14 lessons
57 min

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min