kumaravelk011/model-validation
A Laravel package for validating Eloquent models with rules defined alongside the model. Keep validation close to your data layer, reuse Laravel’s validator, and catch invalid attributes before saving or updating records.
validationRules/validationMessages/validationAttributes and validationData/beforeValidation/afterValidation hooks, for effectively zero cost.skipValidation(), saveWithoutValidation(), and exception-safe Model::withoutValidation(fn () => ...) remove the package's biggest historical objection — the inability to bypass validation. This makes it viable for seeders/fixtures, legacy data imports, backfills, admin "force save" flows, and test factories, which previously forced teams to raw DB writes or to skip the package entirely.laravel/framework for individual illuminate/* components. If a Laravel 12/13 upgrade is already on the roadmap, this aligns cleanly; if you're on Laravel ≤11 or PHP ≤8.1, v2.0.0 is a hard blocker and you stay pinned to 1.x (confirm whether 1.x is still maintained).validate() now returns the validated data array. That makes the model validator usable as the single source of a validated payload (feeding a DTO, event, or downstream job), but it is a behavior change to audit against existing callers.Consider adopting when:
Illuminate\Validation\Validator for edge cases (modelValidator() / ModelValidator::makeValidator()) and an validateOnUpdating() hook alongside the existing saving/creating hooks.Look elsewhere or proceed with caution when:
insert, upsert, mass update). Model event-driven validation does not cover those; the package cannot be your integrity guarantee there.withoutValidation() usage.Migration notes for the decision record: environment bump (PHP 8.2 / Laravel 12+) is the real cost; the models' public API is unchanged (trait name, validate(), validateOnSaving()/validateOnCreating(), config properties, hooks). Audit callers that consumed validate()'s old return value, and re-check Composer resolution now that the package requires individual illuminate/* components rather than laravel/framework.
For executives: "A small, free open-source component that lets us declare validation rules once, on the data model, so every path that writes that data — web forms, background jobs, imports, admin tools — enforces the same rules. The v2 release brings it current with Laravel 12/13 and PHP 8.2, adds an automated test suite and CI, and adds an explicit 'skip validation' switch we need for data imports and backfills. Cost is essentially zero and it removes duplicated rule-writing. The residual risk is that it's a single-maintainer package with no formal support policy — mitigated by keeping our own thin integration tests and treating the dependency as swappable."
For engineering: "Existing model APIs are unchanged — trait, validate(), validateOnSaving()/validateOnCreating(), the rules/messages/attributes config, and the validation hooks all behave as before. What changes: baseline is PHP 8.2 / Laravel 12+, the package now depends on individual illuminate/* components instead of laravel/framework, and validate() returns the validated data array instead of a boolean — grep for callers. The win is skipValidation(), saveWithoutValidation(), and exception-safe Model::withoutValidation(fn () => ...), which finally lets us seed, import, and backfill without fighting validation; plus validateOnUpdating() and a modelValidator() accessor when we need the underlying validator. Design constraint to respect: validation fires on Eloquent model events, so insert/upsert/mass update query-builder calls bypass it — any integrity guarantee must cover those paths explicitly."
How can I help you explore Laravel packages today?