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
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
Next.js Basics for Laravel Developers
11 lessons
58 min
Laravel 13 Eloquent: Expert Level
41 lessons
1 h 34 min