PHP code example of lombokclarion / validation

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

    

lombokclarion / validation example snippets


LombokClarion\Validation

use LombokClarion\Validation\Rule;
use LombokClarion\Validation\Validator;

$rules = [
    'name'  => Rule::uired()->in(['admin', 'editor', 'viewer']),
];

$validator = new Validator($rules);
$violations = $validator->validate($data);

if (!empty($violations)) {
    // $violations[0]->field, ->rule, ->message
}

use LombokClarion\Validation\FormRequest;
use LombokClarion\Validation\Rule;

class CreateWidgetRequest extends FormRequest {
    protected function rules(): array {
        return [
            'name' => Rule::