draw/validator
PHP validation library providing a fluent API to define rules, validate arrays/inputs, and collect errors. Lightweight and framework-agnostic, suitable for Laravel or standalone apps.
if statements, custom regex) with a consistent, declarative approach using Symfony’s Constraint system. This aligns with Laravel’s shift toward modular, reusable components (e.g., Form Requests, API Resources) while introducing Symfony’s maturity.Validator early, avoiding a "big bang" migration.Adopt if:
http-client, messenger) and you want consistent validation patterns.if checks) to a declarative, testable system.password only if changePassword is true).address only on checkout, not cart preview).Look Elsewhere if:
required|email|min:8) and Laravel’s built-in Validator facade suffices.spatie/laravel-validation, laravel-lang/validation) and don’t want dependency bloat.Rule objects).ConstraintViolation requires mapping).Validator is heavier than Laravel’s native validator (benchmark before adopting).For Executives: *"This package lets us future-proof our validation layer by adopting Symfony’s enterprise-grade validator—used by companies like Drupal and Symfony itself—without switching frameworks. It’ll:
@Assert\Email), reuse everywhere. The MIT license and Laravel compatibility make it a low-risk upgrade."For Engineers:
*"The draw/validator package brings Symfony’s Validator to Laravel, giving us:
@Assert\Length(max=255)) and reuse them in controllers, services, or APIs.http-client, messenger) if we adopt them later.For Developers:
*"No more writing if (!filter_var($email, FILTER_VALIDATE_EMAIL)) for every form/API. This lets you validate like this:
use Symfony\Component\Validator\Constraints as Assert;
class UserRegistration {
#[Assert\Email]
#[Assert\NotBlank]
public string $email;
}
Then validate with:
$validator = app(\Symfony\Component\Validator\ValidatorInterface::class);
$errors = $validator->validate($user);
Key perks:
Validator is heavier than Laravel’s native one—benchmark first!"*For Security Teams: *"This package hardens input validation by:
@Assert\Type("string")) at the application boundary.@Assert\Callback for dynamic checks like rate limiting).@Assert\Regex("/^[a-z0-9]+$/") to sanitize usernames before they hit the database."*How can I help you explore Laravel packages today?