rockbuzz/lara-custom-validation

Laravel custom validations

2.1.0 2021-01-22 13:12 UTC

README

Laravel custom validations

Requirements

  • PHP >= 7.2.5
  • Laravel 6+

Install

$ composer require rockbuzz/lara-custom-validation

Available rules

CNPJ

use Rockbuzz\LaraCustomValidation\Rules\CNPJ;

public function rules()
{
    return [
        'field' => [new CNPJ],
    ];
}

CPF

use Rockbuzz\LaraCustomValidation\Rules\CPF;

public function rules()
{
    return [
        'field' => [new CPF],
    ];
}

FullName

use Rockbuzz\LaraCustomValidation\Rules\FullName;

public function rules()
{
    return [
        'field' => [new FullName],
    ];
}

HaveLetters

use Rockbuzz\LaraCustomValidation\Rules\HaveLetters;

public function rules()
{
    return [
        'field' => [new HaveLetters],
    ];
}

HaveNumbers

use Rockbuzz\LaraCustomValidation\Rules\HaveNumbers;

public function rules()
{
    return [
        'field' => [new HaveNumbers],
    ];
}

HaveSpecialCharacters

use Rockbuzz\LaraCustomValidation\Rules\HaveSpecialCharacters;

public function rules()
{
    return [
        'field' => [new HaveSpecialCharacters],
    ];
}

MatchOldPassword

You can optionally pass two parameters in the constructor, the first is $ nullable which by default is false and the $user who by default is auth.

use Rockbuzz\LaraCustomValidation\Rules\MatchOldPassword;

public function rules()
{
    return [
        'field' => [new MatchOldPassword],
    ];
}

Slug

use Rockbuzz\LaraCustomValidation\Rules\Slug;

public function rules()
{
    return [
        'field' => [new Slug],
    ];
}

You can use the extension mode

public function rules()
{
    return [
        'new_password' => 'match_old_password',
    ];
}

Style Code

composer cs

Testing

composer test

License

The Lara Custom Validation is open-sourced software licensed under the MIT license.