mmae / phones
简化手机号码处理的手机类
1.0.0
2024-07-12 22:12 UTC
Requires
- illuminate/support: 11.*
Requires (Dev)
- orchestra/testbench: 9.x-dev
README
laravel 包,简化与手机号码的交互
1. 支持的国家
* Egypt (EG)
* Soudi Arabia (KSA)
* Lybia (LY)
* Qtar (QT)
* Oman (OM)
* Arab Emirates (AU)
* Bahrain (BH)
* kwit (KW)
2. 安装
composer require mmae/phones
3. 使用
- 在保存记录前验证号码
<?php use Illuminate\Http\Request; use MMAE\Phones\EGPhone; class UserController extends App\Http\Controllers\Controller { function store(Request $request) { $data = $request->validate([ 'name' => 'required' 'phone' = 'required' ]) $phone = EGPhone::make($data['phone']); if ($phone->isNotValid()){ return back()->withErrors([ 'phone' => 'wrong format' ]) } $data ['name'] = $phone; // if you save the full version of the number \App\Models\User::create($data); return back()->with('success','created') } }
- 在发送短信前验证号码,如果您支持多国注册
$phone = \MMAE\Phones\Phone::make($user->phone, $user->country_code) if($phone->isNotValid()){ throw new Exception('wrong format') } $SMSService ->message('hello')->to($phone->withPlus())->send()