PHP code example of kdabrow / validation-codes

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

    

kdabrow / validation-codes example snippets




return [
    'fallback_error' => 'E0', // This error code is returned when an error code isn't found in this file
    'accepted' => 'E1',
    'accepted_if' => 'E2',
    'active_url' => 'E3',
    // ...
];



use Illuminate\Contracts\Validation\ValidationRule;

class YourCustomValidationRule implements ValidationRule
{
    public function validate(string $attribute, mixed $value, \Closure $fail): void
    {
        // validation logic
    }

    public static function getCode(): string
    {
        return 'E10000'; // The validation code to return
    }
}



use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class YourServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Validator::extend('your_rule', YourRule::class, 'message', 'E10000');
    }
}
shell
php artisan vendor:publish --tag=validation_codes
shell
docker compose exec php vendor/bin/phpunit