PHPackages                             avto-dev/identity-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. avto-dev/identity-laravel

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

avto-dev/identity-laravel
=========================

IDEntity for Laravel

v6.0.0(2mo ago)329.6k↓100%111MITPHPPHP ^8.1CI passing

Since Feb 6Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/avto-dev/identity-laravel)[ Packagist](https://packagist.org/packages/avto-dev/identity-laravel)[ RSS](/packages/avto-dev-identity-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (36)Used By (1)

 [![IDEntity](https://camo.githubusercontent.com/1402e20d92208983d35ecc99fef7fc0b8685ad6046356d6a56631137c3f8082d/68747470733a2f2f6873746f2e6f72672f776562742f6a7a2f6f752f38682f6a7a6f7538686577656763662d637835667a31716e3633616173612e706e67)](https://camo.githubusercontent.com/1402e20d92208983d35ecc99fef7fc0b8685ad6046356d6a56631137c3f8082d/68747470733a2f2f6873746f2e6f72672f776562742f6a7a2f6f752f38682f6a7a6f7538686577656763662d637835667a31716e3633616173612e706e67)

IDEntity
========

[](#identity)

[![Version](https://camo.githubusercontent.com/a79a2172ee7b0c305911134c41ac2ca26dc250e1a3252fba45c26a3284bde037/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6176746f2d6465762f6964656e746974792d6c61726176656c2e7376673f6d61784167653d313830)](https://packagist.org/packages/avto-dev/identity-laravel)[![PHP Version](https://camo.githubusercontent.com/519adc1d0ef31b90d6f4b6167efa28bed7f7a4090ca481658cd0c613daee14ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6176746f2d6465762f6964656e746974792d6c61726176656c2e7376673f6c6f6e6743616368653d74727565)](https://packagist.org/packages/avto-dev/identity-laravel)[![Build Status](https://camo.githubusercontent.com/cae0cd36309886434744728bb07cf0bc8be10b5224ce234625aed909d89049de/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6176746f2d6465762f6964656e746974792d6c61726176656c2f74657374732e796d6c)](https://github.com/avto-dev/identity-laravel/actions)[![Coverage](https://camo.githubusercontent.com/2d79b5e954ddec0ad36ff8eb43337defac79a7a0ecd992222ab669147015ddeb/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6176746f2d6465762f6964656e746974792d6c61726176656c2f6d61737465722e7376673f6d61784167653d3630)](https://codecov.io/gh/avto-dev/identity-laravel/)[![Downloads count](https://camo.githubusercontent.com/01aae1b6c31de4998bdb9b936fdaf4e6aa83e60bb75b7321f9ee099e8cb267e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6176746f2d6465762f6964656e746974792d6c61726176656c2e7376673f6d61784167653d313830)](https://packagist.org/packages/avto-dev/identity-laravel)[![License](https://camo.githubusercontent.com/72425c2cc94c0d4bcfcbc609b177d1c278471765e10f210a544213da7cf6399b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6176746f2d6465762f6964656e746974792d6c61726176656c2e7376673f6c6f6e6743616368653d74727565)](https://github.com/avto-dev/identity-laravel/blob/master/LICENSE)

**IDEntity** (identification entities) is objects with implemented methods of validation, normalization, and optional automatic type determination.

Installation
------------

[](#installation)

Require this package with composer using the next command:

```
$ composer require avto-dev/identity-laravel "^6.0"
```

> Installed `composer` is required. To install composer, please [click here](https://getcomposer.org/download/).

> Please note that you need to fix the **major** version of the package.

After that you **can** "publish" configuration file (`./config/identity.php`) using next command:

```
$ ./artisan vendor:publish --provider="AvtoDev\IDEntity\ServiceProvider"
```

Usage
-----

[](#usage)

Below you can find some usage examples.

Type detection:

```
use AvtoDev\IDEntity\IDEntity;

IDEntity::is('JF1SJ5LC5DG048667', IDEntity::ID_TYPE_VIN); // true
IDEntity::is('A123AA177', IDEntity::ID_TYPE_VIN); // false

IDEntity::is('JF1SJ5LC5DG048667', IDEntity::ID_TYPE_GRZ); // false
IDEntity::is('A123AA177', IDEntity::ID_TYPE_GRZ); // true

IDEntity::is('14:36:102034:2256', IDEntity::ID_TYPE_CADASTRAL_NUMBER); // true
IDEntity::is('JF1SJ5LC5DG048667', IDEntity::ID_TYPE_CADASTRAL_NUMBER); // false

$valid_vin = IDEntity::make('JF1SJ5LC5DG048667', IDEntity::ID_TYPE_VIN);
$valid_vin->isValid(); // true

$invalid_vin = IDEntity::make('SOME INVALID', IDEntity::ID_TYPE_VIN);
$invalid_vin->isValid(); // false
```

Entities creation:

```
use AvtoDev\IDEntity\IDEntity;
use AvtoDev\IDEntity\Types\IDEntityCadastralNumber;

$vin = IDEntity::make('JF1SJ5LC5DG048667');
$vin->getType();  // 'VIN'
$vin->getValue(); // 'JF1SJ5LC5DG048667'
$vin->isValid();  // true
\get_class($vin); // 'AvtoDev\IDEntity\Types\IDEntityVin'

$cadastral_number = new IDEntityCadastralNumber('10:01:0030104:691');
$cadastral_number->getType(); // 'CADNUM'
$cadastral_number->isValid(); // true
```

> Some typed entity classes contains a lot of additional methods for a working with passed value.

Value normalization:

```
use AvtoDev\IDEntity\IDEntity;
use AvtoDev\IDEntity\Types\IDEntityVin;

$vin = new IDEntityVin(' jf1SJ5LC5DG048 667');
$vin->getValue(); // 'JF1SJ5LC5DG048667'

IDEntity::make('  a123аY777', IDEntity::ID_TYPE_GRZ)->getValue(); // 'А123АУ777'
```

Value masking:

```
