gabeta / lara-pnn
1.0.7
2021-02-21 20:28 UTC
Requires
- php: ^5.5|^5.6|^7.0|^7.1|^7.2|^7.3|^7.4
- gabeta/gsm-detector: ^1.0
Requires (Dev)
- orchestra/testbench: ^3.0|^3.1|^3.2|^3.3|^3.4|^3.5|^3.6|^3.7|^3.8|^4|^5|^6.7
- phpunit/phpunit: ^4|^5|^6|^7|^8|^9
README
Lara-pnn
Lara-pnn 是一个 Laravel 扩展包,允许您以新的科特迪瓦格式格式化您的电话号码(从 8 位数字更改为 10 位数字)。
注意
自 2021 年 1 月 31 日起,科特迪瓦电话号码将更改为 10 位数字,ARTCI 已发布通知以帮助进行迁移。
此包对于具有科特迪瓦电话号码数据库的现有应用程序非常有用。科特迪瓦国家代码为 +225
安装
使用 composer 安装此包。
composer require gabeta/lara-pnn
Laravel 使用包自动发现,因此不需要您手动添加 ServiceProvider。
Laravel 没有自动发现
如果您不使用自动发现,请将 ServiceProvider 添加到 config/app.php 中的 providers 数组。
Gabeta\LaraPnn\laraPnnServiceProvider::class
并在 app.php 中添加以下内容
'LaraPnn' => Gabeta\LaraPnn\Facades\LaraPnn::class,
此包是为科特迪瓦情况设计的,但如果您的情况与科特迪瓦类似,此包处理得非常好。您只需发布并修改包配置文件即可。更多选项请参阅 config/larapnn.php
使用 publish 命令将包配置复制到您的本地配置
php artisan vendor:publish --provider="Gabeta\LaraPnn\laraPnnServiceProvider"
使用方法
准备您的模型
为了使您的模型能够格式化您的科特迪瓦电话号码,模型必须实现以下接口和特性
use Gabeta\LaraPnn\InteractWithLaraPnn; use Gabeta\LaraPnn\LaraPnnAbstract; class YourModel extends Model implements LaraPnnAbstract { use InteractWithLaraPnn; }
然后您必须定义迁移中涉及的字段。
use Gabeta\LaraPnn\InteractWithLaraPnn; use Gabeta\LaraPnn\LaraPnnAbstract; class YourModel extends Model implements LaraPnnAbstract { use InteractWithLaraPnn; protected $pnnFields = [ 'mobile' => ['mobile_field_name'], 'fix' => ['fix_field_name'] ]; }
我们根据拨号代码在迁移之前检查号码的资格,如果拨号代码值在另一个您必须定义的字段中,您必须使用属性 $pnnDialCodeFields
定义
use Gabeta\LaraPnn\InteractWithLaraPnn; use Gabeta\LaraPnn\LaraPnnAbstract; class YourModel extends Model implements LaraPnnAbstract { use InteractWithLaraPnn; protected $pnnFields = [ 'mobile' => ['mobile_field_name'], 'fix' => ['fix_field_name'] ]; protected $pnnDialCodeFields = [ 'mobile_field_name' => 'mobile_dial_code_field_name', 'fix_field_name' => 'fix_dial_code_field_name' ]; }
基本用法:迁移不更改数据库值
您可以基本使用它,这将迁移您的号码而不会修改数据库中的值。
// Before use LaraPnn trait $yourModel->mobile_field_name // 225 09 00 00 00 $yourModel->fix_field_name // 225 20 30 00 00 // After use LaraPnn trait $yourModel->mobile_field_name // 225 07 09 00 00 00 $yourModel->fix_field_name // 225 27 20 30 00 00
高级用法:数据库迁移
对于数据库中号码的迁移,一命令包允许您从单个模式迁移所有号码。
php artisan larapnn:migrate YouModelNamepace\\YourModel
您还有一个命令允许您回滚
php artisan larapnn:rollback YouModelNamepace\\YourModel
您可以添加 take 选项以选择记录
php artisan larapnn:migrate YouModelNamepace\\YourModel --take=50000 php artisan larapnn:rollback YouModelNamepace\\YourModel --take=50000
您可以添加 skip 选项以跳过统计部分(如果您使用计划任务,则使用)
php artisan larapnn:migrate YouModelNamepace\\YourModel --skip php artisan larapnn:rollback YouModelNamepace\\YourModel --skip