PHP code example of kentjerone / laravel-chain-rule

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

    

kentjerone / laravel-chain-rule example snippets


use KentJerone\ChainRule\ChainRule;
use Illuminate\Validation\Rule;

$request->validate([
    'email' => ChainRule::make()
        ->Rule::unique('users', 'id')]),
]);

$age = 20;

$rules = ChainRule::make()
    ->string()
    ->addIfTrue($age >= 18, 'sult: ['string', '

$rules = ChainRule::make()
    ->string()
    ->addIfNotEmpty(['foo'], 'ng', '

$rules = ChainRule::make()
    ->sanitizeXss(['b','i','u','p','a'])

// ✅ passes: <p>Hello <b>World</b></p>
// ❌ fails: <script>alert(1)</script>
// ❌ fails: <a href="javascript:alert(1)">Click</a>

$rules = ChainRule::make()
    ->stripTags(['b','i','u'])

// ✅ passes: <b>bold</b>
// ❌ fails: <div>not allowed</div>

//example 1 helper
$rules1= chainRule()
    ->string()
    ->g()
    ->


//example 1
$rules1 = chainRule()
    ->nullable_string_min_max(1, 255)

// Result: ['string', 'nullable', 'min:1', 'max:255']

//example 2
$rules2 = cr()
    ->nullable_string()

// Result: ['string', 'nullable']