composer require raoul/php-validator
Or
git clone https://github.com/RaoulvanWijk/Validator.git
To use my validator you can either instantiate the validator class
require_once __DIR__ .'/vendor/autoload.php';
use Raoul\Validator\Validator;
$validator = new Validator();
or create a new class that extends the base validator class
require_once __DIR__ .'/vendor/autoload.php';
use Raoul\Validator\Validator;
Class CustomValidator extends Validator
{
public function rules()
{
return [
// Your rules go here
];
}
public function messages()
{
return [
// Your custom messages go here
];
}
}
$validator = new CustomValidator();
And then call the validate method with the needed data
$validator->validate($data);
You have 2 options when specifying the rules when calling the validate method
$validator->validate($data, [
'name' => ['required', 'min:4'],
'email' => 'required|email'
]);
or in the rules() method
public function rules()
{
return [
'name' => ['required', 'min:4'],
'email' => 'required|email'
];
}