Installation:
composer require ysfkaya/filament-phone-input
php artisan filament:assets
php artisan filament-phone-input:install
npm install and npm run build if assets aren't auto-published.First Use Case: Add to a Filament form:
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
PhoneInput::make('phone')
->required()
->label('Contact Number');
validateFor() rules.PhoneInputNumberType constants (E164, NATIONAL, etc.) for display/input formats.Basic Form Integration:
public static function form(Form $form): Form {
return $form->schema([
PhoneInput::make('phone')
->inputNumberFormat(PhoneInputNumberType::E164)
->displayNumberFormat(PhoneInputNumberType::NATIONAL),
]);
}
Separate Country Code Storage:
// Form
PhoneInput::make('phone')
->countryStatePath('phone_country_code');
// Table Column
PhoneColumn::make('phone')
->countryColumn('phone_country_code');
Dynamic Default Country:
PhoneInput::make('phone')
->defaultCountry(fn () => request()->ip() ? 'US' : 'GB');
GeoIP Lookup with Custom Logic:
PhoneInput::make('phone')
->ipLookup(fn () => session('user_country') ?? 'TR');
phone:us|required|mobile).i18n() to override default messages:
PhoneInput::make('phone')
->i18n([
'placeholder' => 'Enter your phone number',
'invalidNumber' => 'Invalid phone number format',
]);
visible()/hidden():
PhoneInput::make('phone')
->visible(fn ($record) => $record->isInternational());
Missing Default Country:
Number requires a country to be specified or Number does not match the provided country.defaultCountry() if storing raw numbers without country codes:
PhoneInput::make('phone')->defaultCountry('US');
Validation Translation:
validation.attributes.phone in resources/lang/en/validation.php.'phone' => 'Phone number',
Country Code Separation:
countryStatePath() in the form and countryColumn() in the table/entry.Asset Conflicts:
intl-tel-input CSS/JS not loading.php artisan filament:assets after installation or manually include:
@vite(['resources/js/app.js', 'node_modules/intl-tel-input/build/js/utils.js'])
dd($record->phone) to verify stored formats (e.g., +12125551234 vs 2125551234).intl-tel-input errors (e.g., missing locales).$phone = Phone::parse('+12125551234', 'US');
$phone->isValid(); // true/false
Custom Options:
PhoneInput::make('phone')
->customOptions([
'separateDialCode' => true,
'initialCountry' => 'auto',
]);
Override Templates:
php artisan vendor:publish --tag=filament-phone-input-views and modify:
resources/views/vendor/filament-phone-input/phone-input.blade.php.Extend Validation:
use Propaganistas\LaravelPhone\Rules\Phone as PhoneRule;
PhoneInput::make('phone')
->rules([
new PhoneRule(['US', 'GB']),
'required',
]);
GeoIP Fallback:
PhoneInput::make('phone')
->ipLookup(fn () => optional($_SERVER['HTTP_X_FORWARDED_FOR']) ?? request()->ip())
->disableLookup(); // Disable auto-lookup if using custom logic
countrySearch() for large country lists:
PhoneInput::make('phone')->countrySearch(false);
useFullscreenPopup() for better mobile input:
PhoneInput::make('phone')->useFullscreenPopup();
PhoneInputNumberType::E164 for consistent testing:
PhoneInput::make('phone')->inputNumberFormat(PhoneInputNumberType::E164);
How can I help you explore Laravel packages today?