You can give field names aliases. This can be handy if an input field name is different from the name you expect for i.e. your database entity.
use KrisKuiper\Validator\Validator;
$data = [
'product' => '1850048',
'code' => '0718037893532',
];
$validator = new Validator($data);
//Create an alias for product and code
$validator->alias('product', 'product_id');
$validator->alias('code', 'ean');
//Add rules for the two new aliases
$validator->field('product_id')->isInt()->min(1);
$validator->field('ean')->isString()->length(13);
//Execute the validation
$validator->execute();
//Retrieve the validated data
print_r($validator->validatedData()->toArray());
This will return:
[
'product_id' => '1850048',
'ean' => '0718037893532'
]
Note: aliases can also be used in blueprints.
Go to the previous section.
Go to the next section.