1. Go to this page and download the library: Download aeunius/laravel-peru-rules library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Aeunius\PeruRules\Enums\TipoDocumento;
use Aeunius\PeruRules\Rules\DocumentoIdentidad;
use Illuminate\Validation\Rule;
$request->validate([
'tipo_doc' => ['
use Aeunius\PeruRules\ValueObjects\Ruc;
class Cliente extends Model
{
protected function casts(): array
{
return [
'ruc' => Ruc::class, // o RucCast::class
];
}
}
$cliente->ruc->valor(); // "20131312955"
$cliente->ruc->formateado(); // "20-13131295-5"
$cliente->ruc->tipo(); // TipoContribuyente::Juridica
$cliente->ruc->esJuridica(); // true
$cliente->ruc->dni(); // null; en un RUC 10 da los 8 dígitos del DNI
$cliente->ruc = '20100047218'; // o un entero, o un objeto Ruc
$cliente->ruc = '20100047219'; // InvalidArgumentException
Ruc::from('20131312955'); // Ruc, o InvalidArgumentException
Ruc::tryFrom('20131312956'); // null
use Aeunius\PeruRules\Support\CciValidator;
use Aeunius\PeruRules\Support\CelularValidator;
use Aeunius\PeruRules\Support\PlacaVehicularValidator;
CelularValidator::normalizar('+51 987 654 321'); // "987654321"
PlacaVehicularValidator::normalizar('abc123'); // "ABC-123"
PlacaVehicularValidator::normalizar('e GA-123'); // "EGA-123"
PlacaVehicularValidator::normalizar('2171ay'); // "2171-AY"
CciValidator::normalizar('002-191-000123456789-57'); // "00219100012345678957"
CelularValidator::normalizar('014567890'); // null: no es un celular