cherif/algerian-mobile-phone-number
AlgerianMobilePhoneNumber), which is ideal for representing domain entities like phone numbers in a type-safe manner.composer require installation with no Laravel-specific dependencies, reducing friction.User phone number field) via accessors/mutators or casts.PHPUnit or Pest).+2136XXXXXXXX).
AlgerianPhoneNumber::fromRequest($request)).libphonenumber (Google’s library) or egulias/email-validator-style packages.Laravel Compatibility:
AlgerianMobilePhoneNumber::fromString($request->phone)).hasMany/belongsTo relationships (must store as string).algerian_phone_number enum).Alternative Stacks:
06-99-00-00-00 → valid object).isMobilis(), isDjezzy()).+213699000000, 0799000000).use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber;
use Illuminate\Validation\Rule;
Rule::macro('algerian_phone', function () {
return function ($attribute, $value, $fail) {
try {
AlgerianMobilePhoneNumber::fromString($value);
} catch (\InvalidArgumentException) {
$fail('The '.$attribute.' must be a valid Algerian mobile number.');
}
};
});
use Illuminate\Database\Eloquent\Casts\Attribute;
protected function phoneNumber(): Attribute {
return Attribute::make(
get: fn ($value) => $value,
set: fn ($value) => AlgerianMobilePhoneNumber::fromString($value)->asString(),
);
}
composer.json or fork the repo.InvalidArgumentException).LIKE or = queries.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Invalid phone number input | Rejected with exception | Use try-catch in validation layer. |
| Package breaks in PHP 8.2+ | Integration fails | Fork/replace or pin to v0.5.0. |
| Carrier codes change (e.g., new ISP) | isMobilis() returns false |
Extend package or add custom logic. |
| Database migration issues | Downtime if schema changes | Test migrations in staging first. |
| High-volume API abuse | Validation overhead | Cache validated numbers (e.g., Redis). |
How can I help you explore Laravel packages today?