Skip to content
Devix Open Source

Guide

Getting started

Validate, store and display phone numbers in Laravel with the same rules the Phone Input widget uses in the browser.

1. Install

composer require devix-labs/laravel-phone

The service provider registers itself. Requires PHP 8.2+ and Laravel 11 or newer (tested on 12). No other packages are installed: the numbering-plan data ships inside the package.

Optionally set the country used for numbers typed without a calling code:

PHONE_DEFAULT_COUNTRY=AE

2. Validate

use Devix\Phone\Laravel\Rules\Phone;

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

Or as a string: 'phone' => 'required|phone:AE,SA,mobile'.

When a number fails, the message says why — too short, too long, needs its area code, must be a mobile number — in English, Arabic or Urdu.

3. Store and read

use Devix\Phone\Laravel\Casts\AsPhoneNumber;
use Devix\Phone\Laravel\Concerns\HasPhoneNumbers;

class User extends Model
{
    use HasPhoneNumbers;

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

$user->phone = '050 123 4567';   // stored as +971501234567
$user->phone->national();         // "050 123 4567"
$user->phone->whatsappUrl();      // "https://wa.me/971501234567"

User::wherePhone('phone', '+971 (0)50 123 4567')->first();

4. Render the field

<form method="POST" action="/profile">
    @csrf
    <label for="phone">Phone</label>
    <x-phone-input name="phone" country="AE" :preferred="['AE', 'SA', 'PK']" required />
</form>

That's a plain <input type="tel"> that works without JavaScript, upgraded to the full widget: searchable countries, flags, formatting as you type and live validation. It posts phone and phone_country, and the rule reads both.

Without Laravel

The core has no framework dependency:

use Devix\Phone\PhoneNumber;

$phone = PhoneNumber::parse('0300 1234567', 'PK');
$phone->isValid();   // true
$phone->e164();      // "+923001234567"
$phone->reason();    // Reason::Valid

Installing from devix.pk

Every release is also a zip on this site's Download button. Unzip it into your project (for example packages/laravel-phone) and add a path repository:

{
    "repositories": [{ "type": "path", "url": "packages/laravel-phone" }],
    "require": { "devix-labs/laravel-phone": "^1.0" }
}
Updated 15 Sep 2026