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
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,766,035 143
isbkch/laravel5-tail

A tail command for Laravel 5

1,266 1
skysplit/laravel5-intl-translation

Laravel 5 package for better translation syntax using php-intl extension

106,829 10
sh0umik/laravel5-mailjet-5.3-fix

Mailjet driver for Laravel 5 with 5.3 Fix

781 0
pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

87,905 19