Skip to content

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

Notifications You must be signed in to change notification settings

sanduluca/validation-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Validation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages