A PHP package that allows you to handling form request validation.
satanvir/validator is a Laravel package for a php package that allows you to handling form request validation..
It currently has 0 GitHub stars and 2 downloads on Packagist.
Install it with composer require satanvir/validator.
Discover more Laravel packages by satanvir
or browse all Laravel packages to compare alternatives.
Last updated
A PHP package that allows you to handling form request validation.
You can install the package via composer:
composer require satanvir/validator
Here's an example of how to use this Validator package for validating input reques:
use Satanvir\Validator\Validator;
$validator = new Validator($config); // Validator(array $config = [])
$validator->request($_POST); // Validator::request(array $inputs): self
You can define rules by two ways.
$rules = [
'name' => 'required|min:3|max:60',
'email' => ['required', 'email']
];
$validator->rules($rules); // Validator::rules(array $rules): self
$validator->rule('email', 'required|email'); // Validator::rule(string $name, array|string $rule): self
$validator->validate(); // Validator::validate(): self
*** This method validate the given inputs by using the given rules ***
if ($validator->fails()) {
// do something
}
// Validator::fails(): bool
*** Return true if validation failed ***
if ($validator->passed()) {
// do something
}
// Validator::passed(): bool
*** Return true if validation passed ***
foreach ($validator->errors() as $error) {
// do something
}
// Validator::errors(): array
*** errors() method returns all generated errors from validators ***
foreach ($validator->error('email') as $error) {
// do something
}
// Validator::error(string $name): array
echo $validator->errorFirst();
//or
echo $validator->errorFirst('email');
// Validator:errorFirst(?string $name = null): ?string
*** if did not pass any param, then return first error from all otherwise return from specific input. ***