- Is yiisoft/validator a Laravel package?
- No. yiisoft/validator is a framework-agnostic Yii3 validation library that works in any PHP project, but it ships no Laravel service provider, facade, Blade or MessageBag integration, and no database-aware rules. In a Laravel codebase it sits underneath the framework rather than inside it, so you must write and own the glue code yourself. It is a reasonable tactical dependency for domain-layer validation, but it is not a drop-in replacement for Illuminate\Validation.
- How do I install yiisoft/validator with Composer?
- Install it with composer require yiisoft/validator, then confirm the package's PHP floor and its transitive Yii dependencies before committing. Pin an exact version, commit the lockfile, and review the changelog on every bump because the package is community-maintained by the Yii core team. Also check that it does not pull in PSR-7 or PSR-15 stacks you do not need.
- Can I use yiisoft/validator instead of Laravel's validator for form requests?
- You can, but you probably should not. Illuminate\Validation already handles HTTP ingress, form requests, authorization-coupled rules, and database checks with better ergonomics for Laravel developers. Keep Yii Validator confined to domain and application invariants such as value objects, command DTOs, and imported payloads. Running two validation grammars across one codebase invites drift and silent-bypass bugs.
- How do I map yiisoft/validator errors into a Laravel MessageBag?
- Write a small result mapper that walks the library's Result and error tree and converts attribute-specific messages into a Laravel MessageBag, keyed by the same attribute names your views and API envelopes expect. That keeps @error directives, Inertia error props, and JSON error responses working unchanged. This adapter is small but is yours to maintain forever, so publish it as a thin internal package rather than duplicating it in feature code.
- How do I handle error message translation for yiisoft/validator in Laravel?
- Implement Yiisoft\Translator\TranslatorInterface as a bridge over Laravel's Translator so the library resolves messages through your existing lang files. Translation keys and message text will not match Laravel's built-in rules one to one, so expect to author new message fixtures and translate them separately. Budget time for that i18n parity work during your spike rather than after rollout.
- Which PHP and Laravel versions does yiisoft/validator support?
- Treat Laravel 10 through 12 on PHP 8.2 and above as the target and verify the library's declared PHP floor and dependency constraints before committing. Because this is a Yii3 package, its version bounds track Yii's roadmap rather than Laravel's release cycle. Confirm compatibility against your supported matrix and re-check on every Laravel upgrade.
- Does yiisoft/validator support nested arrays, object graphs, and attribute-based rules?
- Yes. It validates nested arrays and object graphs and supports rule metadata via attributes, alongside reusable validator classes and structured, attribute-specific error messages. To use attribute-based rules on DTOs in Laravel you need a container binding so rule objects and attribute metadata resolve through Laravel's container, and you should verify attribute discovery still works under OPcache. Be aware that attribute rules are invisible to developers used to $request->validate(), which raises silent-bypass risk if a DTO is persisted without being validated.
- Does yiisoft/validator include database rules like unique and exists?
- No. The library is framework-agnostic and has no Eloquent or database awareness, so unique, exists, and other query-backed checks are not part of it. Keep those checks in Laravel form requests or dedicated rule objects where the database connection is already available. Do not port Illuminate rules one to one; re-express only the invariants that genuinely belong to the domain.
- What are the alternatives to yiisoft/validator for domain validation in Laravel?
- The closest options are Symfony Validator with attribute-based constraints, Respect\Validation for fluent standalone rule chains, or plain Laravel rule objects and custom rules invoked outside the request lifecycle. Each trades framework coupling against adapter work. If your only goal is validating DTOs and value objects inside a Laravel app, a small set of first-party rule classes is often cheaper than adding a second validation grammar.
- Is yiisoft/validator safe to use in production?
- It is BSD-3-Clause licensed with no commercial support and a best-effort community SLA, maintained by the Yii core team with a modest star count, so bus factor and roadmap depend on Yii3 adoption. Pin an exact version, keep a vendored-fork exit path available, and run a bounded pilot in one non-customer-critical context before wider use. The organizational risk is the larger one: forbid direct imports outside your internal adapter package, enforce it with a static-analysis rule, and set a 90-day gate to expand, hold, or sunset.