Weave Code
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

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Standardization of Validation Logic: Replace fragmented validation checks (e.g., manual 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.
  • API-First Validation: Enable machine-readable validation for APIs (e.g., OpenAPI/Swagger schemas, GraphQL inputs) by leveraging Symfony’s constraint-based validation, which maps cleanly to standardized formats like JSON Schema.
  • Business Rule Enforcement: Centralize domain-specific validation (e.g., "order total must exceed $50 for free shipping") in a single layer, reducing logic duplication across controllers, services, and jobs.
  • Migration to Symfony Ecosystem: Prepare for future adoption of Symfony UX, API Platform, or Mercure by adopting Symfony’s Validator early, avoiding a "big bang" migration.
  • Security Hardening: Mitigate injection attacks (e.g., malformed JSON, SQLi via user input) by enforcing strict validation at the application boundary (APIs) and business logic layer (forms, commands).

When to Consider This Package

  • Adopt if:

    • Your team is building complex APIs where input validation must align with OpenAPI/Swagger or GraphQL schemas (Symfony’s constraints map directly to these standards).
    • You need reusable validation rules across multiple layers (e.g., Form Requests, CLI commands, queue jobs) without duplicating logic.
    • Your project uses Symfony components (e.g., http-client, messenger) and you want consistent validation patterns.
    • You’re migrating from monolithic validation (e.g., spaghetti if checks) to a declarative, testable system.
    • You require advanced validation features not in Laravel’s core:
      • Cascading constraints (e.g., validate password only if changePassword is true).
      • Custom constraint validators (e.g., "username must not match a banned list").
      • Validation groups (e.g., validate address only on checkout, not cart preview).
  • Look Elsewhere if:

    • Your validation needs are simple (e.g., required|email|min:8) and Laravel’s built-in Validator facade suffices.
    • You’re heavily invested in Laravel’s validation ecosystem (e.g., spatie/laravel-validation, laravel-lang/validation) and don’t want dependency bloat.
    • Your team lacks Symfony experience and prefers Laravel-native solutions (e.g., Form Requests, Rule objects).
    • You need real-time frontend validation (e.g., Vue/React) and want Laravel’s native JSON error responses (Symfony’s ConstraintViolation requires mapping).
    • Performance is critical for high-throughput APIs: Symfony’s Validator is heavier than Laravel’s native validator (benchmark before adopting).

How to Pitch It (Stakeholders)

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:

  • Reduce bugs from bad data (e.g., malformed API calls, broken forms) by enforcing rules declaratively.
  • Save dev time by reusing validation logic across APIs, forms, and CLI tools.
  • Align with API standards (OpenAPI/Swagger) for better tooling and compliance. Think of it as ‘validation as code’: define rules once (e.g., @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:

  • Declarative validation: Define rules with annotations or YAML (e.g., @Assert\Length(max=255)) and reuse them in controllers, services, or APIs.
  • Custom constraints: Extend validation with business logic (e.g., ‘order must have at least 3 items’) via simple classes.
  • Symfony interop: Works seamlessly with Symfony components (e.g., http-client, messenger) if we adopt them later.
  • API-first: Maps cleanly to OpenAPI/Swagger for automated API documentation. Tradeoffs: Tiny learning curve (Symfony’s docs are robust), but zero stars means we’d own maintenance. Worth it if we’re doing heavy validation or planning to use Symfony tools."*

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:

  • Reusable rules: Define constraints once, use in Form Requests, APIs, or CLI.
  • Advanced features: Validate nested objects, use callbacks, or group constraints.
  • API-friendly: Errors format like Swagger/OpenAPI for tooling support. Downside: Symfony’s Validator is heavier than Laravel’s native one—benchmark first!"*

For Security Teams: *"This package hardens input validation by:

  • Enforcing strict typing (e.g., @Assert\Type("string")) at the application boundary.
  • Supporting custom security constraints (e.g., @Assert\Callback for dynamic checks like rate limiting).
  • Reducing injection risks by validating early (APIs) and often (forms, commands). Example: Add @Assert\Regex("/^[a-z0-9]+$/") to sanitize usernames before they hit the database."*
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor