Allows to use cherif/algerian-mobile-number in Laravel

v0.1.0 2020-09-17 17:02 UTC

This package is auto-updated.

Last update: 2023-03-06 22:36:36 UTC


Allows to use cherif/algerian-mobile-phone-number value object with Laravel.


The recommended way of installation is by using Packagist and Composer.

The following command should be executed in order to add the package as a requirement to composer.json of a project:

$ composer require cherif/algerian-mobile-phone-number-laravel


The package have 2 main classes to use Cherif\AlgerianMobilePhoneNumber\Laravel\Casts\AlgerianMobilePhoneNumberCast and Cherif\AlgerianMobilePhoneNumber\Laravel\Rules\AlgerianMobilePhoneNumberRule to cast models attributes from/to the phone number value object and validate the request respectively:

Eloquent model attribute casting:

To use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber value object instance as Eloquent model attribute use the casting class in the casts model's property like the following:

namespace App\Models;

use Cherif\AlgerianMobilePhoneNumber\Laravel\Casts\AlgerianMobilePhoneNumberCast;
use Illuminate\Database\Eloquent\Model;

class Customer extends Model
    protected $casts = [
        'mobile_phone_number' => AlgerianMobilePhoneNumberCast::class

The definition above allows to use the mobile_phone_number as value object when reading the attribute, the casting to string value will be handled during setting the value and persisting the model in the database.


The mobile phone validator is Cherif\AlgerianMobilePhoneNumber\Laravel\Rules\AlgerianMobilePhoneNumberRule it can be used with the request to validate the input:

use Cherif\AlgerianMobilePhoneNumber\Laravel\Rules\AlgerianMobilePhoneNumberRule;

// ... 

 * Store a new customer.
 * @param  Request  $request
 * @return Response
public function store(Request $request)
    $validatedData = $request->validate([
        'mobilePhoneNumber' => ['required', new AlgerianMobilePhoneNumberRule],

    // The customer is valid...


Contributions are welcome to make this library better.

  • Clone the repo:
$ git clone

and enter to the cloned repository directory.

  • Install dependencies:
$ composer install


$ ./vendor/bin/phpunit


MIT License.