https://github.com/yieldstudio/nova-phone-field
Nova Phone Number field with a dynamic mask based on the country code inserted by the user.
https://github.com/yieldstudio/nova-phone-field
laravel mask nova phone
Last synced: 3 months ago
JSON representation
Nova Phone Number field with a dynamic mask based on the country code inserted by the user.
- Host: GitHub
- URL: https://github.com/yieldstudio/nova-phone-field
- Owner: YieldStudio
- License: other
- Created: 2022-06-01T12:19:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T23:00:59.000Z (about 2 years ago)
- Last Synced: 2025-08-27T03:04:59.660Z (10 months ago)
- Topics: laravel, mask, nova, phone
- Language: Vue
- Homepage:
- Size: 1.36 MB
- Stars: 6
- Watchers: 2
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# A global Phone Number field for Laravel Nova
[](https://github.com/yieldstudio/nova-phone-field/releases)
[](https://packagist.org/packages/yieldstudio/nova-phone-field)
Nova Phone Number field with a dynamic mask based on the country code inserted by the user.
Fork from [bissolli/nova-phone-field](https://github.com/bissolli/nova-phone-field) to maintain package.

## Requirements
- PHP **8.0+**
- Laravel Nova **4.0+**
- Laravel Framework **8.0+**
**NOTE**: For Laravel version < 8.0 or Nova < 4 use [bissolli/nova-phone-field](https://github.com/bissolli/nova-phone-field).
## Installation
You can install this package into a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
```bash
composer require yieldstudio/nova-phone-field
```
## Usage
Go straight to your Nova resource and use `YieldStudio\NovaPhoneField\PhoneNumber` field:
```php
namespace App\Nova;
use YieldStudio\NovaPhoneField\PhoneNumber;
class Member extends Resource
{
// ...
public function fields(Request $request)
{
return [
// ...
PhoneNumber::make('Phone Number'),
// ...
];
}
}
```
Now you can view and add tags on the blog posts screen in your Nova app. All tags will be saved in the `tags` table.
### Filtering
By default, every country mask available inside `yieldstudio/nova-phone-field/resources/js/data/phone-masks.json` will be loaded and working. However, you can always select the desired countries calling the `onlyCountries()` method.
```php
PhoneNumber::make('Phone Number')
->onlyCountries('BR', 'US', 'IE'),
```
### Custom number format
You can also add custom phone formats with `withCustomFormats()`.
```php
PhoneNumber::make('Phone Number')
->withCustomFormats('+123 ## #.#', '+123 ## ####.####'),
```
Or else use only your own phone formats calling for `withCustomFormats()` among with `onlyCustomFormats()`.
```php
PhoneNumber::make('Phone Number')
->withCustomFormats('+123 ## #.#', '+123 ## ####.####')
->onlyCustomFormats(),
```
## Migrate from 1.0.x
In 2.0 values are now stored in [E.164 format](https://en.wikipedia.org/wiki/E.164). Previously, the formatted value was stored, which later caused problems for usage.
With the E.164 format, you can use the phone number directly. We use [libphonenumber-js](https://www.npmjs.com/package/libphonenumber-js) to format it on the Index and Detail of your resources.
To replace previously saved values you can use this query :
```sql
UPDATE _table_ SET _field_=CONCAT('+', REGEXP_REPLACE(_field_, '\\D', ''))
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you've found a bug regarding security please mail [contact@yieldstudio.fr](mailto:contact@yieldstudio.fr) instead of using the issue tracker.
## Credits
- [James Hemery](https://github.com/jameshemery)
- [Gustavo Bissolli](https://github.com/bissolli)
- Special thanks to [Robin Herbots](https://github.com/RobinHerbots) who built one of the best [InputMask](https://github.com/RobinHerbots/Inputmask) from the internet.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.