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
Laravel Ruleset Validation

Laravel Ruleset Validation Laravel Package

craftcms/laravel-ruleset-validation

Validate Laravel request data against Craft CMS field rulesets. Map Craft-style constraints (required, min/max, regex, etc.) into Laravel’s validator, keeping validation logic consistent between Craft and Laravel apps.

View on GitHub
Deep Wiki
Context7

Validate requests and objects with reusable Laravel rulesets.

Frequently asked questions about Laravel Ruleset Validation
How does this package differ from Laravel’s built-in FormRequest validation?
While FormRequest validation works well for HTTP requests, this package extends that by letting you define reusable rulesets as standalone classes. This is ideal for validating non-request objects (e.g., domain models) or sharing logic across multiple FormRequests without duplicating code. Think of it as a way to abstract validation rules into modular, testable components.
Can I use this for API validation in Laravel 10+?
Yes, it’s designed to work seamlessly with Laravel’s API validation ecosystem. You can attach rulesets to FormRequests, manually validate API payloads with `Validator::make($data, $ruleset)`, or even use it in GraphQL resolvers. The package leverages Laravel’s existing validation system, so no extra middleware or middleware changes are needed.
What’s the performance impact of using rulesets vs. inline validation?
The performance overhead is negligible because rulesets are compiled once (like Laravel’s cached validation rules). For large-scale APIs, benchmarks suggest minimal runtime differences, but the real win is maintainability—rulesets reduce duplicated logic and make validation logic reusable across endpoints, services, or even microservices.
How do I migrate existing FormRequest validation to this package?
Start by extracting common validation logic from your FormRequests into reusable ruleset classes. For example, if multiple FormRequests validate an email and password, create a `UserRuleset` class. Then, replace inline rules in your FormRequests with calls to `Validator::make($data, new UserRuleset)`. This can be done incrementally—no need to rewrite everything at once.
Does this support nested or recursive validation (e.g., arrays of objects)?
Yes, the package supports nested validation out of the box. You can define rules for arrays, nested objects, or recursive structures (e.g., `orders.items` or `user.addresses`). The syntax mirrors Laravel’s native validation rules, so you can use `required`, `array`, `object`, or custom rules for complex data shapes. Documentation should cover examples for common nested scenarios.
What Laravel versions are supported, and are there breaking changes?
The package is built for Laravel 10+ and assumes PHP 8.1+ features like named arguments or attributes. If you’re on an older Laravel version, you may need to refactor or use a compatible fork. There are no breaking changes if you follow Laravel’s validation API, but always check the package’s changelog for version-specific updates.
How do I test validation rulesets in PHPUnit or Pest?
Rulesets can be tested independently using PHPUnit or Pest by creating test cases that validate sample data against your ruleset. For example, you can assert that `Validator::make($invalidData, new UserRuleset)->fails()` or `Validator::make($validData, new UserRuleset)->passes()`. The package likely includes helper methods or traits to simplify testing.
Can I extend or customize validation rules beyond Laravel’s defaults?
Absolutely. You can extend Laravel’s built-in validation rules or create custom rulesets for domain-specific logic. For example, you might add a `CustomRuleset` for business rules like `isPremiumUser()` or `meetsShippingRequirements()`. The package integrates with Laravel’s `Validator::extend()` system, so you can reuse or override rules as needed.
What alternatives exist, and when should I choose this package?
Alternatives include Laravel’s native FormRequest validation, `spatie/laravel-validation-rules` (for custom rules), or `laravel-policy` (for authorization). Choose this package if you need reusable, centralized validation logic across APIs, forms, and domain objects—especially in Craft CMS or complex applications where validation rules are duplicated or hard to maintain.
How do I handle validation errors or customize error messages in rulesets?
Error messages can be customized per rule within the ruleset, just like in Laravel’s native validation. Use the `->message()` method or define custom messages in your ruleset class. For example, `email|required|email:rfc,dns,spf,spf_record,catchall,no_mx_record:message=Invalid email format` lets you override the default error text. The package should follow Laravel’s error message conventions.
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.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed