Configuration

Configure default validation behavior, AJAX, styling, and message handling through config/client-validation.php.

Laravel Client Validation publishes a single configuration file, config/client-validation.php, that controls how the browser bundle is loaded and how validation behaves by default.

Publishing and editing config

If you skipped the installer, publish the configuration manually:

php artisan vendor:publish --tag=client-validation-config

Then edit the generated file in your application.

Core runtime options

Use these settings to decide when validation runs and whether server-backed rules are allowed.

return [
    'auto_include_assets' => true,
    'enable_ajax_validation' => true,
    'ajax_timeout' => 5000,
    'route_prefix' => 'client-validation',
    'validation_mode' => 'blur',
    'debounce_ms' => 300,
    'auto_bind_livewire' => true,
];
Option Environment variable Default Effect
auto_include_assets CLIENT_VALIDATION_AUTO_INCLUDE true Injects the bundle via @clientValidationAssets
enable_ajax_validation CLIENT_VALIDATION_ENABLE_AJAX true Allows remote rules (unique, exists, etc.) to hit the backend
ajax_timeout CLIENT_VALIDATION_AJAX_TIMEOUT 5000 Milliseconds before an AJAX validation request times out
route_prefix CLIENT_VALIDATION_ROUTE_PREFIX client-validation URL prefix for the validation endpoint
validation_mode CLIENT_VALIDATION_MODE blur Default trigger: blur, input, live, submit, or form
debounce_ms CLIENT_VALIDATION_DEBOUNCE 300 Debounce for input/live modes
auto_bind_livewire CLIENT_VALIDATION_AUTO_BIND_LIVEWIRE true Auto-registers Livewire component hook and field binding
  • Keep validation_mode at blur for most text fields.
  • Switch to input or live only when feedback needs to be immediate.
  • Leave enable_ajax_validation enabled if you use unique, exists, password, or other server-side rules.
  • Leave auto_bind_livewire enabled unless you only use the manual x-wire-validate directive; see Livewire.

Rate limiting and caching

AJAX validation is throttled and cached to avoid spamming the backend while the user types.

'rate_limit' => [
    'max_attempts' => 60,
    'decay_seconds' => 60,
],

'cache' => [
    'enabled' => true,
    'ttl' => 300,
    'max_size' => 1000,
],

Use a lower debounce or lower rate limit only when you have confirmed the validation endpoint can tolerate the extra traffic.

Error templates and field styling

The package can add and remove CSS classes automatically when a field passes or fails validation.

'error_template' => [
    'enabled' => true,
    'container_class' => 'validation-error text-red-500 text-sm mt-1',
    'show_on' => ['fail'],
    'position' => 'after',
],

'field_styling' => [
    'enabled' => true,
    'valid_class' => 'is-valid border-green-500',
    'invalid_class' => 'is-invalid border-red-500',
],

This is a good place to align the generated classes with your Tailwind, Bootstrap, or bespoke utility classes.

Default messages and attributes

Message placeholders are merged with per-form messages, so keep the config file focused on cross-application defaults.

'messages' => [
    'required' => 'The :attribute field is required.',
    'email' => 'The :attribute must be a valid email address.',
],

'attributes' => [
    'password_confirmation' => 'password confirmation',
],

Rule capability lists

The configuration file also keeps track of which rules are treated as fully client-side and which rules should always use the server.

'client_side_rules' => [
    'required', 'email', 'min', 'max', 'between', 'confirmed',
],

'server_side_rules' => [
    'unique', 'exists', 'password', 'current_password', 'encoding',
],

Only adjust those lists when you are extending the package itself and you fully understand how the parser and browser runtime treat the rule.

Example environment overrides

CLIENT_VALIDATION_AUTO_INCLUDE=true
CLIENT_VALIDATION_ENABLE_AJAX=true
CLIENT_VALIDATION_AJAX_TIMEOUT=7000
CLIENT_VALIDATION_RATE_LIMIT=30
CLIENT_VALIDATION_RATE_DECAY=60
CLIENT_VALIDATION_MODE=blur
CLIENT_VALIDATION_DEBOUNCE=250
CLIENT_VALIDATION_AUTO_BIND_LIVEWIRE=true

CLIENT_VALIDATION_AUTO_BIND_LIVEWIRE=false disables automatic Livewire binding: no component hook is registered and fields must be validated manually with x-wire-validate.