PHP code example of ohtyap / laravel-sane-validator

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

    

ohtyap / laravel-sane-validator example snippets


public function boot(): void
{
    $this->app->extend('validator', function (Factory $factory) {
        $factory->resolver(function (Translator $translator, array $data, array $rules, array $messages, array $attributes) {
            return new \Ohtyap\LaravelSaneValidator\Validator($translator, $data, $rules, $messages, $attributes);
        });

        return $factory;
    });
}

$rules = ['email' => 'email'];
$data = ['email' => ' '];

Validator::make($data, $rules)->passes(); // true

# `laravel-sane-validator` behavior
$validator = Validator::make($data, $rules);
$validator->passes();

# laravel default behavior
$validator = Validator::make($data, $rules);
$validator->disableSaneValidation();
$validator->passes();

public function boot(): void
{
    \Ohtyap\LaravelSaneValidator\Validator::defaultEnableSaneValidation(false);
}

# `laravel-sane-validator` behavior
$validator = Validator::make($data, $rules);
$validator->enableSaneValidation();
$validator->passes();

# laravel default behavior
$validator = Validator::make($data, $rules);
$validator->passes();