PHP code example of ez-php / validation

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

    

ez-php / validation example snippets


use EzPhp\Validation\Validator;

$validator = Validator::make(
    data: ['email' => '[email protected]', 'age' => 17],
    rules: [
        'email' => 'be at least 18.']]
}

// Or throw on failure:
$validator->validate(); // throws ValidationException

use EzPhp\Validation\FormRequest;

class StoreUserRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true; // check e.g. Auth::user()->isAdmin()
    }

    public function rules(): array
    {
        return [
            'name'  => '

public function store(StoreUserRequest $request): Response
{
    // reaches here only if validation and authorization passed
    $data = $request->validated();
}

$translator = $app->make(\EzPhp\I18n\Translator::class);

$validator = Validator::make($data, $rules, translator: $translator);
bash
composer 
bash
composer