ggbear/validation

Standalone library to use Illuminate\Validation package outside the Laravel framework.

1.0.1 2020-07-25 10:31 UTC

This package is auto-updated.

Last update: 2024-05-25 19:12:17 UTC


README

Standalone library to use Illuminate\Validation package outside the Laravel framework.

Install Validation:

  • execute
composer require ggbear/validation

Usage

require_once __DIR__ . '\..\vendor\autoload.php';
/** @var Factory $validatorFactory */
$validatorFactory = new ValidatorFactory();

$number = '123456789012a';
$id = 123;
$string = 'string value';
$channel = 'UNKNOWN';

$input = [
    'number' => $number,
    'id' => $id,
    'string' => $string,
    'channel' => $channel
];
$rules = [
    'number' => 'required|integer|digits_between:11,12',
    'id' => 'required|integer',
    'string' => 'required|string',
    'channel' => 'required|string|in:WEB,API,SOCKET',
];
$validator = $validatorFactory->make($input, $rules);

This will return an instance of Illuminate\Validation\Validator::class.



if ($validator->fails()) {
    print_r($validator->errors()->toArray());
} else {
    echo 'Validaton passed.' . PHP_EOL;
}

You can learn more about the Laravel Validator in the official documentation website.

About validation rules