Skip to content
Devix Open Source
Laravel package v1.1.0 MIT Alpha

Laravel Phone

Phone validation, casts and a Blade component that agree with Phone Input exactly.

composer require devix/laravel-phone
PHP Laravel
Rule playground Open

The server half of Phone Input: a PhoneNumber object, a validation rule with a clear message for every reason, an E.164 cast with a search scope, and <x-phone-input> with Livewire support. No libphonenumber-for-php; rules load one country at a time.

What you get

Agrees with the browser

Same compiled metadata and a line-for-line port of Phone Input's core, proven on 17,568 inputs every release.

Errors with a reason

Too short, needs its area code, must be a mobile number — with a real example number, in English, Arabic and Urdu.

Cast and search

Store E.164, get a PhoneNumber back, and find any number with wherePhone() however it was typed.

A real Blade field

<x-phone-input> works without JavaScript, upgrades to the widget, and binds wire:model to the full number.

Light

No libphonenumber-for-php. Rules load one country at a time from PHP arrays OPcache keeps in memory.

Handy extras

$request->phone(), masked(), whatsappUrl(), formatFor(), localized country search.

Install

composer require devix/laravel-phone
use Devix\Phone\Laravel\Rules\Phone;

$request->validate([
    'phone' => ['required', Phone::rule()->country('AE', 'SA')->mobile()],
]);

Why another Laravel phone package?

Because validating in two places with two different rulebooks is how good numbers get rejected. The browser says a number is fine, the server says it isn't, and the user sees The phone field must be a valid number with no idea why.

Devix Laravel Phone is the server half of Phone Input. It reads the same compiled libphonenumber metadata and runs the same algorithms, ported line for line. Every release proves the two agree on more than 17,000 inputs.

use Devix\Phone\Laravel\Rules\Phone;

$request->validate([
    'phone' => ['required', Phone::rule()->country('AE', 'SA', 'PK')->mobile()],
]);

What the user sees

They typed Message
050 1 The phone is too short.
04 234 5678 in a mobile-only field The phone must be a mobile number.
+44 7400 123456 where only UAE, Saudi and Pakistan are allowed The phone must be a number from United Arab Emirates, Saudi Arabia or Pakistan.
050 123 4567 where a calling code is required The phone must include the country code, like +971 50 123 4567.
٠٥٠١٢٣٤٥٦٧ with an Arabic keyboard Accepted, stored as +971501234567

Store once, use everywhere

protected function casts(): array
{
    return ['phone' => AsPhoneNumber::class];
}

$customer->phone->international();              // "+971 50 123 4567"
$customer->phone->masked();                     // "+971 50 ••• 4567"
$customer->phone->whatsappUrl('Order #1042');   // "https://wa.me/971501234567?text=Order%20%231042"

Customer::wherePhone('phone', '050-123-4567', 'AE')->first();

The field, too

<x-phone-input name="phone" country="AE" :preferred="['AE', 'SA', 'PK']" required />

It renders a plain <input type="tel"> that works before JavaScript loads, then becomes the full Phone Input widget: searchable countries, flags, formatting as you type, and live validation whose messages match the server's wording.

How it compares

Questions

Do I need Phone Input on the frontend?

No. The rule, cast and PhoneNumber object work on their own. Pair them with <x-phone-input> or @devix/phone-input and you also get validation that matches in the browser.

Does it work outside Laravel?

Yes. PhoneNumber, Countries and the engine have no framework dependency — only PHP 8.2 and mbstring.

How accurate is it?

It uses libphonenumber's metadata for 254 regions and every example number validates with the right type. The PHP engine gives the same answer as the JavaScript core on every one of 17,568 test inputs.

Can I switch from propaganistas/laravel-phone?

Yes. The rule parameters and the <field>_country convention are the same, and the migration guide maps every cast and method.

Is it free for commercial use?

Yes, MIT licensed. The bundled metadata is Apache-2.0 from libphonenumber.