Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Hydrator Validator

Hydrator Validator Laravel Package

yiisoft/hydrator-validator

Integrates Yii Hydrator with Yii Validator to validate input data while hydrating typed objects and DTOs. Map arrays into objects and enforce validation rules in one step, reducing boilerplate and keeping data checks close to object construction.

Deep Wiki
Context7

A hydrator that also does validation, including raw data.

Frequently asked questions about Hydrator Validator
What is yiisoft/hydrator-validator used for?
It wraps a Yii hydrator so that raw input data is validated with yiisoft/validator before any object is populated. You map arrays, decoded JSON, or form payloads onto typed PHP objects and enforce validation rules in the same pass. The goal is to keep invalid data out of your domain objects and to keep validation and hydration concerns separate.
Can I use yiisoft/hydrator-validator in a Laravel application?
Yes, mechanically it works. It is a framework-agnostic Yii3 component with no service provider and no global state, it installs via Composer with PSR-4 autoloading, and its constructor-injected collaborators can be satisfied through explicit Laravel container bindings. The friction is idiomatic rather than technical: nothing wires itself, and rules, messages, and localization live in a parallel system to Laravel's own validation.
Does yiisoft/hydrator-validator replace Laravel Form Requests or Illuminate\Validation?
No, and it should not be positioned that way. Laravel developers expect $request->validated(), MessageBag, and ValidationException-driven 422 responses, and this package provides none of that glue. Adopting it means deliberately stepping outside those conventions for the specific domains where you apply it. For ordinary HTTP form input, a Form Request plus a typed constructor is still the shorter path.
How do I install and wire yiisoft/hydrator-validator in Laravel?
Install it with Composer alongside yiisoft/hydrator and yiisoft/validator. You then construct the hydrator and validator yourself and bind them in a service provider, because the package ships no Laravel integration, facade, or Artisan tooling. Expect to write an adapter layer that resolves collaborators from the container and translates Yii validation errors into your application's error shape. Budget real engineering time for that seam instead of assuming configuration alone will cover it.
Which PHP and Laravel versions does yiisoft/hydrator-validator support?
It targets PHP 8.x and installs into modern Laravel 10, 11, and 12 applications via PSR-4 and Composer. Check the exact constraints on Packagist before committing, because Yii3 component API surfaces are still settling and minor version bumps can be breaking in practice. Also verify transitive constraints from yiisoft/validator and yiisoft/hydrator against your existing PSR dependencies during composer update.
How do I test hydration and validation with yiisoft/hydrator-validator?
Both the hydrator and the validator are plain objects, so you can unit test them directly without booting a Laravel application or making HTTP calls. Feed valid arrays and assert the populated object, then feed invalid payloads and assert the expected validation errors surface before construction happens. Cover your adapter layer as well, since that is where most integration bugs will actually live.
How do I return a 422 response from Yii validator errors in Laravel?
Nothing does this automatically. You need adapter code that catches the validation errors your wrapper raises and converts them into a Laravel ValidationException or a manual JSON response with a 422 status. Attribute names, message wording, and localization all come from the Yii side, so translating them into your lang/validation.php conventions is part of the work. Keep that translation in a single place so two validation systems do not drift apart.
Does yiisoft/hydrator-validator support nested objects and collections?
Yes, the Yii hydrator handles nested typed objects and collections of objects, which is one of the main reasons to reach for it. In a Laravel codebase you will usually need adapter code to make nested DTOs feel natural beside Eloquent models and collections. Plan for that mapping layer explicitly rather than discovering it halfway through implementation.
How does yiisoft/hydrator-validator compare to spatie/laravel-data?
Both hydrate typed objects from raw arrays and validate along the way, but spatie/laravel-data is built for Laravel while this package is built for Yii. The Yii option gives you attribute-driven rules and a clean separation between validation and hydration, with no Laravel-specific assumptions baked in. The Laravel-native option gives you framework conventions, community answers, and far less adapter code. For most Laravel teams the honest question is what this solves that a Form Request plus a typed constructor does not.
Is yiisoft/hydrator-validator safe to use in production and who maintains it?
The code is generally well-engineered and strictly typed, licensed BSD-3-Clause and safe for proprietary use. The real risk is strategic isolation: the project has very little community gravity, so there are few blog posts, few Stack Overflow answers, and virtually no Laravel-adjacent tutorials. You would be among the first teams running this combination, which means every edge case is yours to debug. Confine adoption to a bounded pilot such as webhook ingest, queue job deserialization, or CSV import, and keep exit cost low by not letting Yii validator attributes leak into your domain objects.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console