2017 © Pedro Peláez
 

library validation

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator

image

iyoworks/validation

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator

  • Sunday, February 8, 2015
  • by iyoworks
  • Repository
  • 1 Watchers
  • 1 Stars
  • 118 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Validation

Provides a base class to implement validation as a service., (*1)

BaseValidator

Extend the BaseValidator to create your own validation classes., (*2)

use Iyoworks\Validation\BaseValidator;

class FieldValidator extends BaseValidator{

    protected $rules = [
    'name' => 'required',
    'handle' => 'required|unique:fields,handle',
    'fieldtype' => 'required',
    'id' => 'exists:fields,id'
    ];

    //executed 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() {}
}

Next instantiate your validator, (*3)

$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
}

The Versions

08/02 2015

dev-master

9999999-dev

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator

  Sources   Download

The Requires

 

The Development Requires

laravel validation laravel 5

14/01 2015

v1.0

1.0.0.0

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator

  Sources   Download

The Requires

 

The Development Requires

laravel validation laravel 4

24/05 2014

v1.0.0-beta

1.0.0.0-beta

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator

  Sources   Download

The Requires

 

The Development Requires

laravel validation laravel 4