Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cherifgsoul/algerian-mobile-phone-number-laravel
Ability to Use cherif/php-algerian-mobile-phone-number in Laravel framework
https://github.com/cherifgsoul/algerian-mobile-phone-number-laravel
eloquent hacktoberfest hacktoberfest2022 laravel php
Last synced: 3 months ago
JSON representation
Ability to Use cherif/php-algerian-mobile-phone-number in Laravel framework
- Host: GitHub
- URL: https://github.com/cherifgsoul/algerian-mobile-phone-number-laravel
- Owner: cherifGsoul
- License: mit
- Created: 2020-09-17T16:30:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-06T17:10:50.000Z (over 4 years ago)
- Last Synced: 2024-04-17T05:34:50.861Z (9 months ago)
- Topics: eloquent, hacktoberfest, hacktoberfest2022, laravel, php
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cherif/algerian-mobile-phone-number-laravel
Allows to use [cherif/algerian-mobile-phone-number](https://github.com/cherifGsoul/php-algerian-mobile-phone-number) value object with [Laravel](https://laravel.com/).
## Installtion
The recommended way of installation is by using [Packagist](https://packagist.org/packages/cherif/algerian-mobile-phone-number-laravel) and [Composer](http://getcomposer.org/).The following command should be executed in order to add the package as a requirement to `composer.json` of a project:
```shell
$ 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:
```php
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:
```php
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:
```shell
$ git clone [email protected]:cherifGsoul/algerian-mobile-phone-laravel.git
```and enter to the cloned repository directory.
- Install dependencies:
```shell
$ composer install
```### Testing:
```shell
$ ./vendor/bin/phpunit
```## License
[MIT License](LICENSE).