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

Validator Laravel Package

symfony/validator

The Symfony Validator component provides tools to validate values following the JSR-303 Bean Validation specification, with constraints, annotations, and attributes for expressive, reusable validation rules.

View on GitHub
Deep Wiki
Context7

Symfony Validator is a standalone PHP component for validating values according to the JSR-303 Bean Validation specification. It lets you declare constraints as attributes, annotations, XML, or YAML, then validate objects and arrays with a clean, extensible API that integrates seamlessly with Symfony and other frameworks.

  • Rich constraint library covering required fields, types, ranges, formats, and custom rules
  • Multiple mapping formats including PHP attributes, XML, and YAML
  • Flexible validation of single values, nested objects, and collections
  • Localized, customizable error messages via built-in translations
  • Extensible design for writing your own constraints and validators
Frequently asked questions about Validator
How do I install symfony/validator in a Laravel app?
Install it with Composer using composer require symfony/validator. Laravel already pulls in Symfony Validator indirectly through illuminate/validation, but a direct requirement lets you use ValidatorBuilder and Symfony constraints explicitly. If you plan to inject the validator, bind Symfony's ValidatorInterface in a Laravel service provider.
Is symfony/validator compatible with Laravel's built-in validator?
Yes. Laravel's Illuminate Validation layer already uses Symfony Validator under the hood, so the two are compatible by design. You can keep using the Validator facade while adding Symfony constraints for object-level or API payload validation. Direct use is possible with minimal changes.
How do I use Symfony Validator constraints instead of Laravel validation rules?
Create Symfony constraints such as NotBlank, Email, Length, or Range, then validate data with ValidatorBuilder::create()->getValidator()->validate(). You can map common Laravel rules to equivalent constraints or write custom Constraint and ConstraintValidator classes for domain-specific rules. Inspect the returned ConstraintViolationList for errors.
How do I create a custom constraint in Symfony Validator for Laravel business rules?
Extend Symfony's Constraint class and pair it with a ConstraintValidator that implements the validate method. Register the constraint through PHP attributes, YAML/XML mapping, or by adding it to the validator configuration. Unit test the validator directly so complex business rules remain reliable.
What are validation groups and how do they help in Laravel forms and APIs?
Validation groups let you apply different constraint sets to the same object for scenarios such as Default, Create, and Update. Pass the group names when calling validate, and use GroupSequence when order matters. This is useful for multi-step forms, admin versus public API payloads, and reused domain objects.
Does symfony/validator work with Laravel 10, 11, and PHP 8.2+?
Laravel's validation layer already depends on Symfony Validator, so version alignment is the main concern. Symfony Validator 8.x requires PHP 8.4+, while Laravel 10 and later may run on PHP 8.2 or 8.3, so choose a compatible Symfony version or upgrade PHP. Check Composer constraints before adopting a specific major version.
What are the performance considerations for Symfony Validator in production Laravel apps?
Symfony Validator can use compiled metadata through ValidatorBuilder, which reduces repeated configuration work in production. Enable attribute mapping where appropriate and cache metadata during deployment. Lazy loading constraints and avoiding unnecessary validation groups can also reduce overhead in large applications.
How do I format Symfony ConstraintViolationList errors for Laravel API responses?
Iterate the ConstraintViolationList and read getPropertyPath and getMessage for each violation. Map those values into your API's error shape, such as Laravel-style field arrays or JSON:API errors. Return a 422 response and keep formatting consistent with existing Laravel validation responses.
Can I migrate existing Laravel validation rules to Symfony constraints?
Common Laravel rules such as required, email, min, max, and regex map reasonably well to NotBlank, Email, Length, Range, and Regex constraints. Database-aware rules like exists and unique often need custom constraints or should remain in Laravel's request validation layer. Migrate incrementally and keep feature tests around the validation behavior.
What are alternatives to symfony/validator for Laravel validation?
Laravel's built-in Validator facade is the default alternative and covers most request validation needs. Other options include Respect/Validation, JSON Schema validators, or custom rule objects. Symfony Validator is strongest when you need JSR-303-style constraints, validation groups, and object graph validation.
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.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core