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

Validation Laravel Package

respect/validation

Powerful PHP validation engine with 150+ tested validators. Build readable, chainable rules like numeric()->positive()->between(). Includes advanced exception handling and thorough docs. Great for complex input validation in any PHP app.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. Buy: Buy – Eliminates the need to build a custom validation layer from scratch, reducing technical debt and accelerating development.
  • Feature Roadmap:
    • API/Forms Validation: Replace manual checks with fluent, declarative validation (e.g., v::email()->notBlank()->assert($input)).
    • Data Integrity: Enforce business rules (e.g., v::between(18, 120)->validate($user['age'])) in Laravel models, API requests, or CLI commands.
    • Error Handling: Centralize validation errors with structured ResultQuery objects for consistent UX (e.g., API responses, frontend feedback).
    • Attribute-Based Validation: Leverage PHP 8+ attributes for type-safe validation (e.g., #[Email] public string $email in DTOs).
    • Dynamic Validation: Support conditional rules (e.g., v::factory(fn($input) => v::key('confirmation', v::equals($input['password'])))).
  • Use Cases:
    • Laravel API Controllers: Validate incoming requests (e.g., Request objects) with reusable pipelines.
    • Form Requests: Replace FormRequest::rules() with fluent validation for complex logic (e.g., nested arrays, custom business rules).
    • Domain Models: Validate entities (e.g., User, Order) during creation/update via v::attributes().
    • CLI/Console Commands: Validate user input in artisan commands (e.g., v::numericVal()->positive()->assert($input)).
    • Testing: Assert validation logic in unit/feature tests (e.g., v::email()->assert($email)).
    • Legacy Code Modernization: Replace ad-hoc if/elseif validation chains with maintainable, composable rules.

When to Consider This Package

  • Adopt if:
    • Your team needs >150 built-in validators (e.g., emails, dates, numeric ranges, custom regex) without writing boilerplate.
    • You’re using PHP 8.5+ (v3.0+ requirement) and want modern features like attribute validation or result composition.
    • You prioritize fluent, chainable syntax over Laravel’s Validator facade (e.g., v::numericVal()->between(1, 100) vs. ['min', 'max']).
    • Your validation logic is complex (nested arrays, dynamic rules, short-circuiting) or requires custom error messages/templates.
    • You need fine-grained error inspection (e.g., ResultQuery for API error responses with paths like .user.address.city).
    • Your project uses Laravel but wants to avoid vendor lock-in (this package is framework-agnostic).
  • Look elsewhere if:
    • You’re on PHP <8.5 (use v2.x, but it lacks v3’s features).
    • Your validation needs are simple (e.g., basic Laravel FormRequest rules suffice).
    • You require deep Laravel integration (e.g., Validator::extend(), Rule objects) and prefer ecosystem-native solutions.
    • Your team lacks PHP 8+ familiarity (attributes, named args, union types) for advanced features.
    • You need real-time validation (e.g., frontend JS libraries like Vue Formulate) and only want backend validation for persistence.

How to Pitch It (Stakeholders)

For Executives:

"Respect\Validation is a battle-tested, MIT-licensed PHP package that replaces manual or ad-hoc validation with a maintainable, composable system. It reduces bugs in user input handling by enforcing rules declaratively (e.g., v::email()->notBlank()), cuts development time by 30–50% for validation-heavy features, and improves data quality across APIs, forms, and CLI tools. With >150 validators and support for complex nested validation, it’s ideal for scaling Laravel applications while keeping validation logic DRY and testable. The package’s attribute-based validation (PHP 8.5+) also aligns with modern OOP practices, making it future-proof."

ROI:

  • Dev Velocity: Reuse validators across controllers, commands, and tests.
  • Quality: Centralized rules reduce inconsistent validation logic.
  • Scalability: Handles edge cases (e.g., dynamic rules, short-circuiting) without custom code.

For Engineers:

*"This package lets you write validation once, use it everywhere—whether in Laravel API requests, domain models, or CLI tools. Key advantages:

  • Fluent Syntax: Chain validators like v::numericVal()->positive()->between(1, 100).
  • ResultQuery: Inspect validation failures with paths (e.g., .user.address.city) for granular error reporting.
  • Attributes: Annotate DTOs/models with #[Email], #[Between(18, 120)] for type-safe validation.
  • Dynamic Rules: Create validators at runtime (e.g., v::factory(fn($input) => v::equals($input['password']))).
  • No Laravel Lock-in: Works standalone or alongside Laravel’s Validator.

Migration Path:

  • Replace FormRequest::rules() with v::email()->notBlank()->assert($request->all()).
  • Use v::attributes() to validate annotated entities.
  • Swap if chains for v::allOf(v::email(), v::notBlank())->assert($input).

Example:

// Before: Manual checks in a controller
if (!filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
    throw new \InvalidArgumentException('Invalid email');
}
if ($request->age < 18) {
    throw new \InvalidArgumentException('Must be 18+');
}

// After: Declarative validation
v::allOf(
    v::email(),
    v::key('age', v::between(18, 120))
)->assert($request->all());
```"*

**Trade-offs**:
- **Learning Curve**: PHP 8.5+ features (attributes, union types) may require team upskilling.
- **Migration Effort**: v3.0 has breaking changes (see [Migration Guide](https://respect-validation.readthedocs.io/en/3.0/migrating-from-v2-to-v3/)).
- **Laravel Integration**: Not a drop-in replacement for `Validator` facade (but can coexist)."
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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