### Installation
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Installs the package via composer and publishes necessary assets.
```bash
composer require ysfkaya/filament-phone-input
php artisan filament:assets
php artisan filament-phone-input:install
```
--------------------------------
### Usage Examples
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Demonstrates how to use the PhoneInput component within Filament's Form, Table, and Infolist builders.
```php
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Infolists;
use Filament\Infolists\Infolist;
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
use Ysfkaya\FilamentPhoneInput\Tables\PhoneColumn;
use Ysfkaya\FilamentPhoneInput\Infolists\PhoneEntry;
use Ysfkaya\FilamentPhoneInput\PhoneInputNumberType;
public static function infolists(Infolist $infolist): Infolist
{
return $infolist
->columns([
Infolists\Components\TextEntry::make('name'),
Tables\Columns\TextColumn::make('email')
->sortable()
->searchable(),
PhoneEntry::make('phone')->displayFormat(PhoneInputNumberType::NATIONAL),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TextInput::make('email')
->required()
->email()
->unique(ignoreRecord: true),
PhoneInput::make('phone'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('email')
->sortable()
->searchable(),
PhoneColumn::make('phone')->displayFormat(PhoneInputNumberType::NATIONAL)
]);
}
```
--------------------------------
### Blade Layout with Scripts
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
An example of a Blade layout file that includes necessary scripts for asynchronous loading and lazy loading of assets, which might be required for components like the phone input.
```html
{{-- views/components/layouts/app.blade.php --}}
{{ $slot }}
@stack('scripts')
```
--------------------------------
### Default Country Configuration
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Explains the importance of setting a default country for phone number parsing and provides an example.
```php
PhoneInput::make('phone')
->defaultCountry('US')
```
--------------------------------
### Set Custom GeoIp Lookup
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Allows setting a custom function for GeoIP lookup to determine the initial country. This can be used to override the default lookup mechanism, for example, by fetching data from an external API.
```php
PhoneInput::make('phone')
->ipLookup(function () {
return rescue(fn () => Http::get('https://ipinfo.io/json')->json('country'), app()->getLocale(), report: false);
})
```
--------------------------------
### Testing Commands
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Provides the Composer commands necessary to prepare the testing environment and run the package's tests.
```bash
composer prepare-test
composer test
```
--------------------------------
### Upgrade Commands
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Lists the Artisan commands to run when upgrading from version 2.x of the package to ensure assets are published correctly.
```bash
php artisan filament:assets
php artisan filament-phone-input:install
```
--------------------------------
### Using PhoneInput in a Livewire Component
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Demonstrates how to integrate the `PhoneInput` component within a Livewire component. It includes setting up the form schema and managing the component's state.
```php
form->fill();
}
public function form(Form $form): Form
{
return $form
->schema([
PhoneInput::make('phone'),
])->statePath('data');
}
public function render()
{
return view('livewire.component');
}
}
```
--------------------------------
### Phone Input Component API
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Provides a comprehensive list of methods for configuring the PhoneInput component in Filament forms.
```APIDOC
PhoneInput::make(string $name)
->countryStatePath(string | Closure $statePath, bool $isStatePathAbsolute)
->validateFor(string | array $country = 'AUTO', int | array | null $type = null, bool $lenient = false)
->defaultCountry(string $value)
->ipLookup(Closure $callback)
->disableLookup()
->enableIpLookup(bool | Closure $value = true)
->inputNumberFormat(PhoneInputNumberType | Closure $format)
->displayNumberFormat(PhoneInputNumberType | Closure $format)
->focusNumberFormat(PhoneInputNumberType | Closure $format)
->placeholderNumberType(PhoneInputNumberType | Closure $format)
->disallowDropdown()
->allowDropdown(bool | Closure $value = true)
->autoPlaceholder(string $value = 'polite')
->containerClass(string | Closure $value)
->countryOrder(array | Closure | null $value)
->countrySearch(bool | Closure $value = true)
->customPlaceholder(string | RawJs | Closure | null $value)
->dropdownContainer(string | null | Closure $value)
->excludeCountries(array | Closure $value)
->fixDropdownWidth(bool | Closure $value = true)
->formatAsYouType(bool | Closure $value = true)
->formatOnDisplay(bool | Closure $value = true)
->i18n(array | Closure $value)
->initialCountry(string | Closure $value)
->nationalMode(bool | Closure $value = true)
->onlyCountries(array | Closure $value)
->showFlags(bool | Closure $value = true)
->separateDialCode(bool | Closure $value = true)
->useFullscreenPopup(bool | Closure $value = true)
->strictMode(bool | Closure $value = true)
->cookieName(string | Closure $value)
->locale(string | Closure $value)
->customOptions(array | Closure $value)
```
--------------------------------
### Troubleshooting NumberParseException
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Provides guidance on resolving the `PropaganistasLaravelPhoneExceptionsNumberParseException` error, primarily by ensuring the default country is correctly set.
```text
- Make sure you have set the [default country](#default-country). If you still receive this error, you can open an issue detailing what you did.
```
--------------------------------
### Show Fullscreen Popup
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Enables a fullscreen popup for country selection on mobile devices using the `useFullscreenPopup` method.
```php
PhoneInput::make('phone')
->useFullscreenPopup(),
```
--------------------------------
### PhoneInput Blade Component Usage
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Shows how to render the `PhoneInput` component within a Blade view, typically used in conjunction with a Livewire component.
```blade
{{-- views/livewire/component.blade.php --}}
{{ $this->form }}
```
--------------------------------
### Filament Phone Input Configuration Options
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
This section details various configuration options available for the Filament Phone Input component, allowing customization of country selection, number formatting, display, and user interface elements. These options can be applied directly within your Filament forms.
```php
$form->schema([
PhoneInput::make('phone')
->separateNumbers()
->defaultCountry('US')
->validation(
'required',
'phone:US,CA'
)
->displayNumberFormat('national')
->inputNumberFormat('e164')
->focusInputType('tel')
->disallowDropdown()
->hideFlags()
->showFullscreenPopup()
->autoPlaceholder('polite')
->customContainerClass('my-custom-container')
->excludeCountries(['US', 'CA'])
->onlyCountries(['GB', 'FR'])
->formatOnDisplay()
->geoIpLookup()
->placeholderNumberType('mobile')
->countryOrder(['GB', 'FR', 'US'])
->countrySearch()
->strictMode()
->cookieName('phone_input_country')
->locale('en')
->i18n(['en' => 'English', 'fr' => 'French'])
->enableFormattingAsYouType()
]);
```
--------------------------------
### Using PhoneInput Outside of Filament
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Demonstrates how to utilize the PhoneInput component outside of the standard Laravel Filament form builder, likely for standalone use in Blade views or other contexts. This showcases the component's flexibility.
```php
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
// In a Blade view or other context:
```
--------------------------------
### Propaganistas\LaravelPhone\Exceptions\NumberParseException Error Handling
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Provides guidance on troubleshooting and resolving the `NumberParseException` that may occur when using the Laravel Phone package, often related to invalid phone number formats or country codes.
```php
// Ensure the phone number is valid and includes the country code if necessary.
// Example of a valid number for US:
$phoneNumber = '+12024171234';
// If using a local format, ensure the default country is set correctly or provide it.
try {
$parsedNumber = phoneNumber($phoneNumber)->formatE164();
} catch (Propaganistas\LaravelPhone\Exceptions\NumberParseException $e) {
// Handle the exception, e.g., log the error or return an error message.
report($e);
// Or return a response indicating the error.
}
```
--------------------------------
### Add Custom Container Classes
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Adds custom CSS classes to the parent div of the phone input component using the `customContainer` method for styling.
```php
PhoneInput::make('phone')
->customContainer('w-full'),
```
--------------------------------
### Set Auto Placeholder
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Configures the auto placeholder behavior for the phone input field using the `autoPlaceholder` method. The default value is 'polite'.
```php
PhoneInput::make('phone')
->autoPlaceholder('aggressive'), // default is 'polite'
```
--------------------------------
### Set Initial Country
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Sets the default country for the phone input component using the `initialCountry` method. Accepts a country code string.
```php
PhoneInput::make('phone')
->initialCountry('us'),
```
--------------------------------
### Set Format On Display
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Determines whether the phone number should be formatted for display. Setting this to false disables formatting. The default behavior is to format on display.
```php
PhoneInput::make('phone')
->formatOnDisplay(false),
```
--------------------------------
### Set Placeholder Number Type
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Specifies the type of number to use for the placeholder in the input field. Accepts predefined types like 'FIXED_LINE'.
```php
PhoneInput::make('phone')
->placeholderNumberType('FIXED_LINE'),
```
--------------------------------
### Separate Country Code
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Shows how to save the country code and phone number in separate database columns using `countryStatePath`.
```php
// Form Input:
PhoneInput::make('phone')
->countryStatePath('phone_country')
// Table Column:
PhoneColumn::make('phone')
->countryColumn('phone_country')
// Infolist Entry:
PhoneEntry::make('phone')
->countryColumn('phone_country')
```
--------------------------------
### Configure i18n for Phone Input
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Configures the internationalization (i18n) settings for the phone input component, allowing customization of country names and other plugin text elements. Refer to the intl-tel-input documentation for a full list of available options.
```php
PhoneInput::make('phone')
->i18n([
// Country names
'fr' => "Frankreich",
'de' => "Deutschland",
'es' => "Spanien",
'it' => "Italien",
'ch' => "Schweiz",
'nl' => "Niederlande",
'at' => "Österreich",
'dk' => "Dänemark",
// Other plugin text
"selectedCountryAriaLabel" =>'Ausgewähltes Land',
"countryListAriaLabel" =>'Liste der Länder',
"searchPlaceholder" =>'Suchen',
]);
```
--------------------------------
### Set Country Order
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Defines the order in which countries appear in the dropdown list using the `countryOrder` method. Accepts an array of country codes.
```php
PhoneInput::make('phone')
->countryOrder(['us', 'gb', 'tr']),
```
--------------------------------
### Enable Strict Mode
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Enables strict mode for the phone input, which ignores irrelevant characters as the user types. This ensures that only valid phone number characters are processed, adhering to the intl-tel-input library's behavior.
```php
PhoneInput::make('phone')
->strictMode();
```
--------------------------------
### Set Display Number Format
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Sets the display format for the phone number using the `displayNumberFormat` method. The default format is NATIONAL. Available formats include E164, INTERNATIONAL, NATIONAL, and RFC3966.
```php
PhoneInput::make('phone')
->displayNumberFormat(PhoneInputNumberType::E164),
```
--------------------------------
### Set Locale for Phone Input
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Sets the locale for the phone input component. By default, it uses the application's locale obtained via `app()->getLocale()`. This method allows overriding it for specific instances.
```php
PhoneInput::make('phone')
->locale('en');
```
--------------------------------
### Disable Format as You Type
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Disables the automatic formatting of the phone number as the user types. This can be useful if you prefer to handle formatting manually or if the automatic formatting interferes with specific input requirements.
```php
PhoneInput::make('phone')
->formatAsYouType(false);
```
--------------------------------
### Set Input Number Format
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Sets the format for the input phone number value, which is typically saved to the database. The default format is E164. This method influences how the phone number is stored.
```php
PhoneInput::make('phone')
->inputNumberFormat(PhoneInputNumberType::NATIONAL),
```
--------------------------------
### Hide Flags
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Hides the country flags in the phone input component using the `showFlags` method with a false argument. This option should be used in conjunction with `separateDialCode` or `disallowDropdown`.
```php
PhoneInput::make('phone')
->showFlags(false),
```
--------------------------------
### Disable Dropdown
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Disables the country code dropdown selector in the phone input component using the `disallowDropdown` method.
```php
PhoneInput::make('phone')
->disallowDropdown(),
```
--------------------------------
### Change Cookie Name for IP Lookup
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Allows customization of the cookie name used to store the selected country when the IP lookup feature is active. The default name is 'intlTelInputSelectedCountry'.
```php
PhoneInput::make('phone')
->cookieName('myCookieName');
```
--------------------------------
### Set Only Countries
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Restricts the available countries in the dropdown to a specified list using the `onlyCountries` method. Accepts an array of country codes.
```php
PhoneInput::make('phone')
->onlyCountries(['tr','us', 'gb']),
```
--------------------------------
### Validate Phone Number
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Validates a phone number using the `validateFor` method. It allows specifying the country, type of phone number (mobile or fixed line), and a lenient validation mode. Dependencies include the libPhoneNumber library.
```php
PhoneInput::make('phone')
->validateFor(
country: 'TR' | ['US', 'GB'], // default: 'AUTO'
type: libPhoneNumberType::MOBILE | libPhoneNumberType::FIXED_LINE, // default: null
lenient: true, // default: false
),
```
--------------------------------
### Disable GeoIP Lookup
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Disables the automatic GeoIP lookup feature that sets the initial country when the component mounts. This is done using the `disableLookup` method.
```php
PhoneInput::make('phone')
->disableLookup(),
```
--------------------------------
### Set Focus Input Type
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Configures the input type when the phone number field gains focus. The default value is false. This can be set to specific number types like E164.
```php
PhoneInput::make('phone')
->focusNumberFormat(PhoneInputNumberType::E164),
```
--------------------------------
### Exclude Countries
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Excludes specific countries from the available country list in the dropdown using the `excludeCountries` method. Accepts an array of country codes.
```php
PhoneInput::make('phone')
->excludeCountries(['us', 'gb']),
```
--------------------------------
### Disable Country Search
Source: https://github.com/ysfkaya/filament-phone-input/blob/main/README.md
Disables the default active country search functionality in the phone input component. This is useful when you want to provide a simpler input experience.
```php
PhoneInput::make('phone')
->countrySearch(false);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.