1. Go to this page and download the library: Download fadion/validator-assistant 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/ */
fadion / validator-assistant example snippets
class UserValidator extends ValidatorAssistant {
// Validation rules, as you'd define them
// for Laravel's Validator class.
protected $rules = array(
'username' => 'ail is
namespace MyApp\Validators;
// If the alias was added
use ValidatorAssistant;
// Without alias
use Fadion\ValidatorAssistant\ValidatorAssistant;
class UserValidator extends ValidatorAssistant {}
$userValidator = UserValidator::make(Input::all());
if ($userValidator->fails()) {
return Redirect::back()->withInput()->withErrors($userValidator->instance());
}
$userValidator = UserValidator::make();
// is the sames as
$userValidator = UserValidator::make(Input::all());
protected $filters = array(
'title[sq]' => 'trim|ucfirst',
'title[en]' => 'trim|ucwords'
);
// or with the catch-all modifier
protected $filters = array(
'title[*]' => 'trim|upper'
);
$userValidator = UserValidator::make(Input::all());
if ($userValidator->fails()) {
return Redirect::back()->withInput()->withErrors($userValidator->instance());
}
// Will return the filtered input data
$inputs = $userValidator->inputs();
// Validates the 'default' and 'profile' rules combined,
// with the 'profile' ruleset taking precedence
$userValidator = UserValidator::make(Input::all())->scope('profile');
// Validates the 'default' and 'register' rules
$userValidator = UserValidator::make(Input::all())->scope('register');
// Validates the 'default', 'profile' and 'register' rules
$userValidator = UserValidator::make(Input::all())->scope(['profile', 'register']);
// Validates the 'default' rules only
$userValidator = UserValidator::make(Input::all());
class UserValidator extends ValidatorAssistant {
protected $preserveScopeValues = true;
}
[
'username' => '
$userValidator = UserValidator::make(Input::all());
// New rules or messages will be added or overwrite existing ones
$userValidator->addRule('email', '
// The combined rules will be: , 'email|unique:users');
$userValidator = UserValidator::make(Input::all());
// One by one
$userValidator->bind('min', 5);
$userValidator->bind('max', 15);
$userValidator->bind('table', 'users')
$userValidator->bind('date', '2012-12-12');
// As an array
$userValidator->bind([
'min' => 5,
'max' => 15,
'table' => 'users',
'date' => '2012-12-12'
]);
// Overloading
$userValidator->bindMin(5);
$userValidator->bindMax(15);
$userValidator->bindTable('users');
$userValidator->bindDate('2012-12-12');
class UserValidator extends ValidatorAssistant {
protected $rules = array(/* some rules */);
protected function before()
{
// Rules, inputs, filters, attributes and
// messages can be manipulated.
$this->rules['username'] = 'tected function after($validator)
{
if ($validator->fails()) {
// run some code
}
}
}