Download the PHP package theriddleofenigma/laravel-model-validation without Composer
On this page you can find all versions of the php package theriddleofenigma/laravel-model-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download theriddleofenigma/laravel-model-validation
More information about theriddleofenigma/laravel-model-validation
Files in theriddleofenigma/laravel-model-validation
Package laravel-model-validation
Short Description Effortless, self-contained validation for your Eloquent models.
License MIT
Homepage https://github.com/theriddleofenigma/laravel-model-validation
Informations about the package laravel-model-validation
Laravel Model Validation
Effortless, self-contained validation for your Eloquent models.
Keep your validation rules where the data lives. Declare the rules on the model, opt in to the model event you care about, and every save is validated automatically — no form requests, no repeated calls to the validator.
Requirements
| Package | Version |
|---|---|
| PHP | 8.2, 8.3, 8.4 |
| Laravel | 12.x, 13.x |
Laravel 13 requires PHP 8.3 or newer. Older Laravel releases that have reached end-of-life are not supported.
Installation
Quick start
Add the Enigma\ValidatorTrait to a model, declare its rules, and register the
event you want to validate on:
Now any attempt to save an invalid model throws an
Illuminate\Validation\ValidationException, exactly like Laravel's own
validation — so in an HTTP context the errors are flashed and redirected
for you automatically.
Registering validation
Three helpers register the matching Eloquent event listener for you:
Prefer to validate on a different event, or on demand? Call validate()
yourself. It returns the validated data and throws on failure:
Customising the configuration
Rules, messages and attribute names can each be declared either as a property or as a method of the same name. A method always takes precedence, so you can compute the configuration dynamically when you need to.
Controlling the data that gets validated
By default the model's raw attributes are validated. Declare a
validationData() method to reshape that data first — the returned value
is used only for validation and never changes what is persisted.
Skipping validation
Sometimes you need to persist a model without validating it — a seeder, a data import, or an admin override. There are three ways to do it.
Skip it on a single instance and save:
Toggle the flag back on when you need to:
Disable validation for a whole block — the cleanest way to skip it when creating through the query builder:
Validation is automatically re-enabled once the callback finishes, even if it throws.
Before & after hooks
Implement beforeValidation() and/or afterValidation() to run logic around
each validation pass:
Testing
Contributing
Pull requests are welcome! Please read the contributing guide first, make sure the test suite passes, and add coverage for any behaviour you change. Notable changes are tracked in the changelog.
Security
If you discover a security vulnerability, please follow the process in SECURITY.md rather than opening a public issue.
Code of Conduct
This project follows a Code of Conduct. By participating, you are expected to uphold it.
License
Laravel Model Validation is open-sourced software licensed under the MIT license.
All versions of laravel-model-validation with dependencies
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
illuminate/validation Version ^12.0|^13.0