Download the PHP package moonlydays/laravel-mno without Composer
On this page you can find all versions of the php package moonlydays/laravel-mno. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moonlydays/laravel-mno
More information about moonlydays/laravel-mno
Files in moonlydays/laravel-mno
Package laravel-mno
Short Description Utilities for configuring interactions with operator phone numbers and subscribers.
License MIT
Homepage https://github.com/MoonlyDays/laravel-mno
Informations about the package laravel-mno
Laravel MNO
Laravel package for validating, normalizing, and working with MSISDN phone numbers tied to a single Mobile Network
Operator. A wrapper around giggsey/libphonenumber-for-php with
integration into Laravel's validation system, Eloquent casts, Faker, schema builder, and facades.
Released under the MIT License.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
Installation
Publish the configuration file:
Configuration
Set up the environment variables:
| Variable | Description |
|---|---|
MNO_NAME |
Name of the mobile network operator |
MNO_COUNTRY |
ISO 3166-1 alpha-2 country code (e.g., RU, TZ) |
MNO_NETWORK_CODES |
Comma-separated National Destination Code (NDC) prefixes for the operator |
MNO_MIN_LENGTH |
Minimum national number length (optional — inferred from libphonenumber metadata) |
MNO_MAX_LENGTH |
Maximum national number length (optional — inferred from libphonenumber metadata) |
When MNO_MIN_LENGTH / MNO_MAX_LENGTH are unset, the package infers the length from libphonenumber
metadata for the configured country, walking the number_types priority list in config/mno.php
(defaults to Mobile, then General).
Usage
Creating a Msisdn
Msisdn is a lightweight value object wrapping libphonenumber's native PhoneNumber. It implements
Stringable (casting to string produces the E.164 form), JsonSerializable (serializes as E.164), and
Castable (can be used directly as an Eloquent cast). It also uses Laravel's Macroable and Tappable traits.
Formatting
Retrieving number components
Two Msisdn instances can be compared via $a->equals($b) (equality is based on the E.164 form).
Timezones
Validation
Validation failures translate the following keys, which you can publish or override in your own language files:
validation.msisdn.invalidvalidation.msisdn.countryvalidation.msisdn.min_length(receives:min)validation.msisdn.max_length(receives:max)validation.msisdn.network_code
Overriding the default rule
MsisdnRule::defaults() lets you swap in a custom resolver used by Rule::msisdn():
Request macro
The service provider registers a msisdn macro on Illuminate\Http\Request:
Eloquent cast
Since Msisdn implements Castable, you can use it directly as an Eloquent cast. MsisdnCast is
also available if you prefer to be explicit:
The cast accepts a string, integer, or Msisdn instance when setting, and persists the E.164 digits
as an unsigned integer (the leading + is stripped). When reading back, the configured MNO_COUNTRY is
used as the default region for parsing, so make sure it is set.
Back the cast with an unsigned bigInteger column (e.g., $table->unsignedBigInteger('phone')). A
VARCHAR column will break writes.
Faker provider
When the Faker generator resolves from the container, the package registers a provider for generating valid numbers within the configured MNO (country, network codes, and length constraints):
JSON resource
MsisdnFormatResource exposes the operator's format metadata as a JSON resource, for API responses
that need to tell clients about expected number shape:
MNO facade
The facade resolves the MnoService singleton, which is also bound to the container alias mno and can be
injected directly.
Country and Carrier value objects
Artisan command
Inspect the configured MNO, a country, or a specific carrier:
Extending via macros
Msisdn uses the Macroable trait, so you can add project-specific helpers:
All versions of laravel-mno with dependencies
giggsey/libphonenumber-for-php Version ^9.0.27
giggsey/locale Version ^2.9
illuminate/contracts Version ^11.0||^12.0||^13.0
spatie/laravel-package-tools Version ^1.93