Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Algerian Mobile Phone Number Laravel Laravel Package

cherif/algerian-mobile-phone-number-laravel

Laravel integration for the cherif/algerian-mobile-phone-number value object. Provides an Eloquent cast to store/read Algerian mobile numbers as a value object, plus a validation rule for request input. Install via Composer and use in models/forms.

View on GitHub
Deep Wiki
Context7

cherif/algerian-mobile-phone-number-laravel

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

Installtion

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

Usage:

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.

Validation:

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...
}

Contribution

Contributions are welcome to make this library better.

  • Clone the repo:
$ git clone git@github.com:cherifGsoul/algerian-mobile-phone-laravel.git

and enter to the cloned repository directory.

  • Install dependencies:
$ composer install

Testing:

$ ./vendor/bin/phpunit

License

MIT License.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony