New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

iyoworks/validation

Provides a base class to implement validation as a service. Also adds a little sugar to Laravel's validator
129 1
Install
composer require iyoworks/validation
Latest Version:v1.0
Laravel:4
Last Updated:Feb 8, 2015
Links: GitHub  ·  Packagist
Maintainer: iyoworks

Validation

Provides a base class to implement validation as a service.

BaseValidator

Extend the BaseValidator to create your own validation classes.

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

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

Related Packages

schuppo/password-strength

This package provides a validator for ensuring strong passwords in Laravel 4 app...

2,773,769 143
claraleigh/naughty-username

Validate that a username is not a naughty one

24,348 0
cohensive/validation

Extra functionality for Laravel 5 Validator.

13,938 14
jedrzej/validator-extended-syntax

Laravel 4/5 package that adds validator negation to Laravel's validation module

11,595 3
shin1x1/laravel-validator-builder

Laravel 4 Validator builder

7,436 2

Version History

Version Released Laravel License
v1.0 ~4
Pre-releases (1)
Version Released Laravel License
v1.0.0-beta >=4.0