PHP code example of ukeloop / laravel-validation-rule-builder

1. Go to this page and download the library: Download ukeloop/laravel-validation-rule-builder 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/ */

    

ukeloop / laravel-validation-rule-builder example snippets


use Illuminate\Support\Facades\Validator;
use Ukeloop\ValidationRuleBuilder\ValidationRuleBuilder;

Validator::make($input, [
    'title' => (new ValidationRuleBuilder())->

use Ukeloop\ValidationRuleBuilder\ValidationRuleBuilder;

$validationRule = new ValidationRuleBuilder();

$validationRule->ionRule->numeric();
$validationRule->date();
$validationRule->bool();

$validationRule->min(8);
$validationRule->max(255);

$validationRule->email('strict', 'dns');

// etc ...

$validationRule->add(Password::min(8));

new ValidationRuleBuilder(
    function ($attribute, $value, $fail) {
        if ($value === 'foo') {
            $fail('The ' . $attribute . ' is invalid.');
        }
    }
);

use Ukeloop\ValidationRuleBuilder\RuleSet;

class EmailRuleSet extends RuleSet
{
    public static function rules(): ValidationRuleBuilder
    {
        return new ValidationRuleBuilder('email:strict,dns,spoof');
    }
}

use Illuminate\Support\Facades\Validator;

Validator::make($input, [
    'email' => EmailRuleSet::rules()->somtime()->

use Ukeloop\ValidationRuleBuilder\RuleSet;

class PasswordRuleSet extends RuleSet
{
    public static function rules(): ValidationRuleBuilder
    {
        return new ValidationRuleBuilder(
            Password::min(8)
                ->letters()
                ->mixedCase()
                ->numbers()
                ->symbols()
        );
    }
}

use Illuminate\Support\Facades\Validator;

Validator::make($input, [
    'password' => PasswordRuleSet::rules()->