mmae / phones
Phone class that make dealing with phone numbers easy
1.0.0
2024-07-12 22:12 UTC
Requires
- illuminate/support: 11.*
Requires (Dev)
- orchestra/testbench: 9.x-dev
README
laravel package to make interact with phone number easier
1. Supported Countries
* Egypt (EG)
* Soudi Arabia (KSA)
* Lybia (LY)
* Qtar (QT)
* Oman (OM)
* Arab Emirates (AU)
* Bahrain (BH)
* kwit (KW)
2. Installation
composer require mmae/phones
3. Usage
- validate the number before saving the record
<?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') } }
- validate the number before sending sms if you supporting multiple country registration
$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()