Download the PHP package pepperfm/filament-phone-numbers without Composer
On this page you can find all versions of the php package pepperfm/filament-phone-numbers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pepperfm/filament-phone-numbers
More information about pepperfm/filament-phone-numbers
Files in pepperfm/filament-phone-numbers
Package filament-phone-numbers
Short Description A Filament PHP plugin for normalizing phone numbers
License MIT
Homepage https://github.com/pepperfm/filament-phone-numbers
Informations about the package filament-phone-numbers
A Filament PHP plugin for normalizing phone numbers
This package provides a PhoneNumber field, PhoneNumberColumn and PhoneNumberEntry Infolist entry for normalizing, formatting, masking and validating phone numbers in the Filament PHP application builder for Laravel. It also provides an Artisan command for normalizing any phone number data already captured in the database.
It ensures that numbers persisted to the database are in a normalized format, typically E164 (+12345551212), and displays them in National or International format. It supports most of the regional formats by ISO country code.
Think of phone numbers like dates. Regardless of the format you display and input them, you always want them stored in a standard format.
NOTE - if you would rather handle normalizing by casting attributes in your models, and don't need the additional features like normalization of existing data, improved searching and validation this plugin provides, you may prefer to use the excellent Laravel-Phone package.
Installation
NOTE that this package is currently only compatible with Filament v3, and there are currently no plans to release a v2 compatible version.
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
These configuration values define the defaults for all usage of the field and column. They can be overridden on a per field or column basis.
Rather than publishing the config, we recommend using the environment variables.
FILAMENT_PHONE_NUMBERS_ISO_COUNTRY - the standard two letter (alpha-2) ISO country code.
FILAMENT_PHONE_NUMBERS_DATABASE_FORMAT, FILAMENT_PHONE_NUMBERS_DDISPLAY_FORMAT - one of the following integers:
- 0 - E164
- 1 - International
- 2 - National
- 3 - RFC3966
We strongly recommend leaving the database format as E164.
FILAMENT_PHONE_NUMBERS_ICON - any valid Heroicons v2 icon name.
PhoneNumber Field
The simplest usage of the PhoneNumber field is:
This will use your globally configured region, database and display formats.
It will attempt to set a mask based on your region, and will automatically validate the number according to the configured region in "permissive" mode, where it just checks that the number has the correct number of digits.
The full set of options is as follows.
To override the display or database formats, use one of the available PhoneFormat enums:
To enforce a stricter validation, which uses published metadata to determine if a number is "possible", use the strict() method.
Take care using this feature, as metadata may not be fully up-to-date.
To override the globally configured region, use the region() method with a valid two letter (alpha-2) ISO country code.
If the mask automatically applied by the field doesn't do what you want, you can override it with the standard Filament mask() method:
PhoneNumberColumn
The basic usage of the PhoneNumberColumn is:
With no modification, this will use the global default for display format and region.
You may override the format and region, and optionally specify the dial() method, which will render the number as a clickable 'tel' URI:
Searching
With phone numbers normalized to E164, searching for formatted numbers wouldn't usually work out-of-box. For example searching for 555-1212 wouldn't find the number +12345551212. Likewise, searching for (234) won't find it.
To overcome this, we override the default behavior of searchable(). First we check to see if the first character the user typed is an open paren, '('. If so, we assume they are looking for an area code. So we strip any parens, get the country dial code for the currently configured region, and prepend that to the search string. Then we strip all other non-numeric characters from the string. So a search for '(2' with a region of 'US' would get converted to +12. Or '(234) 5' would be '+12345'. If no () are used, we don't prepend the country code, and simply strip non-numeric characters. So 555-1212 becomes 5551212.
If you do not wish to use this behavior (for example if you are not using E164 for your database format, although we strongly recommend that you do) you can add the useDefaultSearch() method, which will bypass the search query modification. Also, if you specify your own $query in a searchable() method, this will bypass our modification.
PhoneNumberEntry
The basic usage of the PhoneNumberEntry Infolist field is as follows:
With no modification, this will use the global default for display format and region.
You may override the format and region, and optionally specify the dial() method, which will render the number as a clickable 'tel' URI:
Artisan Command
We provide an Artisan command for normalizing phone numbers you have already collected in your database table(s).
This will run the command in test mode, whereby no actual changes will be made.
You will be prompted for:
- Model (e.g.
Location
orMaps/Dealership
) - Phone attribute to normalize (e.g. phone or phone_number)
- Attribute to normalize to (e.g. normalized_phone, leave blank to modify in-place)
- Phone Number Format (use E164 unless you have a very good reason not to)
- Two letter (alpha-2) ISO country code (e.g. US or GB)
The command will output feedback like this:
If you wish to remove invalid nunbers from your table, you can provide the --delete-invalid option, which will set invalid numbers to null. NOTE that your database field must be nullable for this to work.
Once you are satisfied that the changes are correct, you can call the command with the --commit option:
... or ...
You can also provide all of the arguments on the command line, if you would rather not be prompted for them, as per the following examples.
Testing
Clone the repo and run ...
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Hugh Messenger
- All Contributors
This plugin also uses the Brick\PhoneNumber package by Benjamin Morel, which itself iss a wrapper around the giggsey/libphonenumber-for-php package, which in turn is based on Google's google/libphonenumber package. Turtles all the way down.
License
The MIT License (MIT). Please see License File for more information.
All versions of filament-phone-numbers with dependencies
brick/phonenumber Version ^0.5.0
calebporzio/sushi Version ^2.4
filament/filament Version ^3.0
illuminate/contracts Version ^10.0|^11.0
spatie/laravel-package-tools Version ^1.15.0