PHP code example of kohkimakimoto / laravel-validator-extension

1. Go to this page and download the library: Download kohkimakimoto/laravel-validator-extension 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/ */

    

kohkimakimoto / laravel-validator-extension example snippets


'aliases' => array(
    ...
    'BaseValidator' => 'Kohkimakimoto\ValidatorExtension\Validator',
),

ClassLoader::addDirectories(array(
    ...
    app_path().'/validators',
));

// app/validators/BlogValidator.php
class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this
            ->rule('title', '

$validator = BlogValidator::make(Input::all());
if ($validator->fails()) {
    return Redirect::back()->withInput(Input::all())->withErrors($validator);
}

// Get only validated data.
$data = $validator->onlyValidData();

class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this->beforeFilter(function($validator){
            // your code
        });

        $this->afterFilter(function($validator){
            // Modify title after validation.
            $title = $validator->title;
            $title .= " created by kohki";
            $validator->title = $title;
        });
    }
}

class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this
            ->rule('title', 'y must be foo only!')
            ;
    }

    protected function validateFoo($attribute, $value, $parameters)
    {
        return $value == 'foo';
    }
}

class BlogValidator extends BaseValidator
{
    public function getTitleOrDefault() {
        if ($this->title === null) {
            return "Default title";
        } else {
            return $this->title;
        }
    }
}

'providers' => array(
    ....
    'Kohkimakimoto\ValidatorExtension\ValidatorExtensionServiceProvider',
}