Skip to content
Bladewell

<x-widget.phone>

Phone Blade component for Laravel and Livewire

A country picker with flags and dial codes, plus the number. Submits one international number, +60123456789. Works with Livewire wire:model.

php artisan bladewell:add phone
Also adds
Icon, Search
Works with
Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+

Usage

Livewire

In a Livewire component, bind with wire:model (deferred) or wire:model.live; no name is needed. The property gets the full international number (+14155550123), whatever country and formatting people pick. Set it in PHP and the field picks the matching country and shows the national number; country only sets where an empty field starts.

Blade
<x-widget.phone label="Phone" country="US" wire:model="phone" />

On the server

The phone can't stop a request that skips it. Here's what to check on your server, and what to keep cheap.

Security

  • The country picker only shapes the number in the browser. Check the format on the server (E.164: regex:/^\+[1-9]\d{6,14}$/, or a phone validation package), and don't treat a number as verified until a code sent to it comes back.

    OWASP: Input validation ยท OWASP: Multi-factor authentication

Server cost

  • If you text the number, each SMS is billed, and some countries cost far more than others. Consider throttling per number and per IP, and only sending to the countries you serve, so the form can't be used to run up texts.

    Laravel: Rate limiting

Examples

Phone

Pick the country, type the number as it's dialled at home. It submits one international number (+60123456789): validate it on the server, for example with propaganistas/laravel-phone. Pasting a full +44 number switches the country. country sets where it starts; otherwise the app locale's region does.

Show code
Blade
<div class="grid gap-6 sm:grid-cols-2">
    <x-widget.phone name="mobile" label="Mobile number" country="MY" placeholder="12-345 6789" required />
    <x-widget.phone name="office" label="Office" value="+442079460958" />
</div>

Props

Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.

<x-widget.phone>

Prop Default Description
name null What it submits as; its error and old input are found under it. Optional with wire:model, which then names it.
id null Defaults to one made from the name (or the wire:model property).
label null Shown above the field, and its name for screen readers.
value null The full international number (+14155550123). Old input wins; with wire:model and no value, the bound property.
country null The country to start with (US); otherwise guessed from the locale.
placeholder null Shown while it's empty.
error null An error message of your own; otherwise the validation error for the name, from the session or Livewire.
info null A hint under the field.
bag 'default' Which error bag to read the error from.
disabled false Greyed out: it can't be changed.
readonly false Shown, and submitted, but it can't be edited.
locale null The language for country names and that guess; defaults to the app's.

Accessibility

The example above is checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.

Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.

Source

What bladewell:add phone writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from the components it also adds and Field, and the theme and base CSS.

resources/views/components/widget/phone/index.blade.php Show
index.blade.php
resources/js/widget/phone/index.js Show
index.js
app/View/Widget/Countries.php Show
Countries.php
app/View/Widget/ElementIds.php Show
ElementIds.php
app/View/Widget/FormField.php Show
FormField.php