Download the PHP package fridzema/laravel-validation-plus without Composer
On this page you can find all versions of the php package fridzema/laravel-validation-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fridzema/laravel-validation-plus
More information about fridzema/laravel-validation-plus
Files in fridzema/laravel-validation-plus
Package laravel-validation-plus
Short Description Non-blocking validation warnings for Laravel
License MIT
Homepage https://github.com/fridzema/laravel-validation-plus
Informations about the package laravel-validation-plus
Laravel Validation Plus
Non-blocking validation warnings for Laravel. Add advisory messages to your form requests that inform users without preventing submission.
How It Works
Warnings are advisory messages that don't block form submission. Unlike validation errors (red, HTTP 422), warnings (amber) let the request through while informing users about potential issues.
Requirements
| Package | PHP | Laravel |
|---|---|---|
| 1.x | ^8.3 | 11.x, 12.x |
Installation
Optionally publish the config:
Add the middleware to routes that need warnings:
Usage
FormRequest
Add the HasWarningRules trait and define warningRules():
Warning rules are evaluated after standard validation passes. If validation fails, warnings are never checked.
| Method | Purpose | Default |
|---|---|---|
warningRules() |
Rules that trigger warnings | [] |
warningMessages() |
Custom warning messages | [] |
warningAttributes() |
Custom field display names (:attribute substitution) |
[] |
Manual Usage
Use WarningValidator directly in controllers:
Blade
A $warnings variable (a WarningBag instance) is automatically shared with all views:
Or use the included component:
Or use the @warning directive (mirrors @error):
API Responses
When the ShareWarnings middleware is active and warnings exist, API responses automatically get:
- An
X-Validation-Warnings: trueheader - Warnings merged into the JSON body under a
"warnings"key
Precognition (Real-Time Validation)
The package integrates with Laravel Precognition for real-time per-field warnings as users type.
| Real-time warnings | Real-time errors |
|---|---|
Add the HandlePrecognitiveRequests middleware to your route:
Warning rules are automatically filtered by the Precognition-Validate-Only header, so only the field being validated is checked.
Warnings are returned in the X-Validation-Warnings-Data response header as JSON:
Frontend Integration
Warnings travel in two ways depending on your setup:
| Request type | Warnings location |
|---|---|
Standard API (Accept: application/json) |
JSON body under warnings key |
Precognition (real-time, Precognition: true) |
X-Validation-Warnings-Data header as JSON |
Axios
An interceptor that surfaces warnings on every response:
Vue 3
React
Alpine.js
Global Warnings
For advisory messages not tied to a specific field:
Access them in Blade with the reserved __global__ key:
Helper Function
Testing
Test macros are registered automatically:
Configuration
Warnings vs Errors
| Errors | Warnings | |
|---|---|---|
| Block request | Yes | No |
| Cause validation failure | Yes | No |
| HTTP status | 422 | 200 (original) |
| Blade variable | $errors |
$warnings |
| Session flash | Automatic | Via middleware |
| API response | Standard Laravel | Header + JSON key |
Octane Compatibility
WarningBag uses a scoped binding and is reset between requests automatically by Laravel Octane. No extra configuration needed.
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-validation-plus with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0