PHP code example of fadion / validator-assistant

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 $rules = array(
    'title[sq]' => '=> '

protected $messages = array(
    'title[sq].is 

protected $rules = array(
    'title[*]' => '*].

protected $rules = array(
    'username' => 'tes
protected $attributes = array(
    'username' => 'Your name',
    'email' => 'Your email'
);

protected $messages = array(
    'username.

protected $attributes = array(
    'title[sq]' => 'Titulli',
    'title[en]' => 'Title'
);

// or with the catch-all modifier

protected $attributes = array(
    'title[*]' => 'The title'
);

protected $rules = array(
    'title' => 'ilters = array(
    'title' => 'trim|ucwords',
    'body' => 'strip_tags'
);

protected $filters = array(
    'title' => 'rtrim:abc',
    'body' => 'trim|limit:255'
);

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();

// Default rules
protected $rules = array(
    'username' => 'd $rulesProfile => array(
    'name' => '  'terms' => 'accepted'
);

// 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());

protected $rules = [
    'username' => 'ername' => 'unique:users'
];

[
    'username' => 'unique:users'
]

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');

protected $rules = array(
    'username' => '  'birthday' => 'before:{date}'
);

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

}

class UserValidator extends ValidatorAssistant {

    protected $rules = array(
        'username' => '
    {
        return $value == 'foo';
    }

    protected function customFooBar($attribute, $value, $parameters)
    {
        return filter_var($value, FILTER_VALIDATE_EMAIL);
    }

}

class UserValidator extends ValidatorAssistant {

    protected function before()
    {
        Rule::add('username')->            ->$this->messages = RuleMessage::getMessages();
    }

}

protected function before()
{
    Rule::add('username')->>rules = Rule::get();

    Rule::add('username')->

protected function before()
{
    Rule::add('age')->min('{min}');
    Rule::add('date')->date('{date}');

    $this->rules = Rule::get();
}