PHP code example of mrpunyapal / laravel-client-validation

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

    

mrpunyapal / laravel-client-validation example snippets


use Livewire\Component;
use MrPunyapal\ClientValidation\Livewire\WithClientValidation;

class CreateUser extends Component
{
    use WithClientValidation;

    public string $name = '';
    public string $email = '';
    public string $password = '';
    public string $password_confirmation = '';

    protected $rules = [
        'name' => '

protected $listeners = [
    'client-validation-error' => 'handleClientError',
    'client-validation-cleared' => 'handleClientCleared',
];

public function handleClientError($data)
{
    // $data = ['field' => 'email', 'errors' => ['The email field is 

use MrPunyapal\ClientValidation\Filament\ClientValidationPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                ClientValidationPlugin::make()
                    ->enableRemoteValidation()
                    ->validationMode('live'),
            ]);
    }
}

use Filament\Forms\Components\Field;
use MrPunyapal\ClientValidation\Filament\HasClientValidation;

class MyField extends Field
{
    use HasClientValidation;
}

use MrPunyapal\ClientValidation\Filament\ClientValidatedField;

ClientValidatedField::make('email')
    ->clientValidation('

use MrPunyapal\ClientValidation\Facades\ClientValidation;

public function create()
{
    $validation = ClientValidation::fromRequest(CreateUserRequest::class);
    return view('users.create', compact('validation'));
}

return [
    'validation_mode' => 'blur',        // 'blur', 'input', 'submit'
    'debounce_ms' => 300,               // Debounce for live validation
    'enable_ajax_validation' => true,   // Enable AJAX for remote rules
    'rate_limit' => [
        'max_attempts' => 60,           // Requests per window (0 = disabled)
        'decay_seconds' => 60,          // Window duration
    ],
    'error_template' => [
        'container_class' => 'text-red-500 text-sm mt-1',
    ],
    'field_styling' => [
        'valid_class' => 'border-green-500',
        'invalid_class' => 'border-red-500',
    ],
];

ClientValidation::extend('strong_password', function ($value) {
    return preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/', $value);
}, 'Password must contain uppercase, lowercase, and numbers.');
bash
php artisan boost:update --discover
javascript
const remote = new RemoteValidator({
    endpoint: '/validate/',
    csrfHeaderName: 'X-CSRFToken',
    csrfTokenResolver: () => document.cookie.match(/csrftoken=([^;]+)/)?.[1]
});
bash
php artisan vendor:publish --tag=client-validation-config