erlenwald/filament-phone-input
Filament v5 phone input field with searchable country picker, favorites, per-country masks, and auto country detection. Configurable output format/state paths, optional country state field, default/IP lookup, and optional SVG flags. No intl-tel-input.
Installation:
composer require erlenwald/filament-phone-input
php artisan vendor:publish --tag=filament-phone-input-assets
php artisan filament:assets
php artisan optimize:clear
Basic Usage:
use Erlenwald\FilamentPhoneInput\PhoneInput;
PhoneInput::make('phone')
->required()
->label('Phone Number');
First Use Case: Add a phone field to a Filament form/resource:
// In a Filament Form or Resource
PhoneInput::make('contact_phone')
->phoneNumberFormat(\Erlenwald\FilamentPhoneInput\Enums\PhoneNumberFormat::E164);
Form Integration:
// In a Filament Form
PhoneInput::make('phone')
->phoneStatePath('normalized_phone')
->countryStatePath('country_code')
->defaultCountry('US');
Resource Usage:
// In a Filament Resource
PhoneInput::make('user_phone')
->countries(['US', 'CA', 'GB'])
->favoriteCountries(['US', 'CA'])
->displayCountryFlag();
Dynamic Configuration:
PhoneInput::make('phone')
->phoneNumberFormat(fn ($record) => $record->preferred_format ?? 'e164')
->countries(fn ($record) => $record->allowed_countries ?? ['US', 'GB']);
Validation Integration:
PhoneInput::make('phone')
->required()
->rules(['regex:/^\+[0-9]{10,15}$/']);
phoneStatePath() and countryStatePath() to customize how data is stored in your database.filament-phone-input-translations) and override country names or labels.PhoneInput::make('phone')
->enableIpLookup()
->ipLookup('/api/ip-country', 'country');
resources/css/vendor/erlenwald/filament-phone-input/phone-input.css.Asset Publishing:
filament-phone-input-assets) will break flag display.filament:assets and optimize:clear after publishing custom CSS or translations.Country Restrictions:
countries() restricts the dropdown, while defaultCountry() only sets a fallback. Ensure these are aligned with your use case.IP Lookup:
Flag Atlas:
State Path Conflicts:
phoneStatePath() without considering existing database columns may lead to missing data or validation errors.public/vendor/erlenwald/filament-phone-input/flags/ after publishing.{"country_code": "US"}).php artisan optimize:clear
php artisan filament:assets
->phoneStatePath(fn ($state) => {
\Log::info('Phone state path:', ['path' => $state]);
return 'custom_phone';
});
Custom Formats:
Extend the PhoneNumberFormat enum or use raw strings for non-standard formats:
->phoneNumberFormat('custom:[+][country_code][number]');
Dynamic Countries: Fetch countries dynamically from an API:
->countries(fn () => collect(http_get('api/countries'))->pluck('code')->toArray())
Custom Validation: Override validation rules in your Form/Resource:
->rules(['phone' => 'required|phone:US,CA,GB']);
Styling:
Override CSS variables in phone-input.css:
.fi-phone-input__input {
--fi-phone-input-input-border-color: #e2e8f0;
}
Translations: Extend published translations for custom country names or labels:
// lang/vendor/erlenwald-filament-phone-input/en/phone-input.php
return [
'countries' => [
'XX' => 'Custom Country Name',
],
];
How can I help you explore Laravel packages today?