yieldstudio/nova-phone-field

Nova Phone Number field with a dynamic mask based on the country code inserted by the user.

Downloads

40654

Stars

6

Version

2.0.0

A global Phone Number field for Laravel Nova

Latest Version Total Downloads

Nova Phone Number field with a dynamic mask based on the country code inserted by the user.

Fork from bissolli/nova-phone-field to maintain package.

screenshot of the phone field

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.

Installation

You can install this package into a Laravel app that uses Nova via composer:

composer require yieldstudio/nova-phone-field

Usage

Go straight to your Nova resource and use YieldStudio\NovaPhoneField\PhoneNumber field:

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.

PhoneNumber::make('Phone Number')
    ->onlyCountries('BR', 'US', 'IE'),

Custom number format

You can also add custom phone formats with withCustomFormats().

PhoneNumber::make('Phone Number')
    ->withCustomFormats('+123 ## #.#', '+123 ## ####.####'),

Or else use only your own phone formats calling for withCustomFormats() among with onlyCustomFormats().

PhoneNumber::make('Phone Number')
    ->withCustomFormats('+123 ## #.#', '+123 ## ####.####')
    ->onlyCustomFormats(),

Migrate from 1.0.x

In 2.0 values are now stored in E.164 format. 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 to format it on the Index and Detail of your resources.

To replace previously saved values you can use this query :

UPDATE _table_ SET _field_=CONCAT('+', REGEXP_REPLACE(_field_, '\\D', ''))

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

YieldStudio

Author

YieldStudio