1. Go to this page and download the library: Download iyoworks/validation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iyoworks / validation example snippets
use Iyoworks\Validation\BaseValidator;
class FieldValidator extends BaseValidator{
protected $rules = [
'name' => 'ed before validation
protected function preValidate() {
if($fieldtype = $this->get('fieldtype'))
{
$this->runner->addDynamic('fieldtype', 'exists', function($value){
return app('fieldtypes')->exists($value);
}, 'Invalid fieldtype given for :attribute attribute');
}
}
//executed before validation on insert mode
protected function preValidateOnInsert() {}
//executed before validation on update mode
protected function preValidateOnUpdate() {
if($this->get('handle'))
$this->setUnique('handle'); // the id will be appended to the rule
}
//executed before validation on delete mode
protected function preValidateOnDelete() {}
}
$validator = new FieldValidator;
$data = ['name' => 'Title', 'order' => 2];
//set the mode and pass your data object
if($validator->validForInsert($data)){
//your logic
} else {
$this->errors = $this->validator->errors();
//more logic
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.