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 Fluent Validation

Laravel Fluent Validation Laravel Package

sandermuller/laravel-fluent-validation

Type-safe, IDE-autocomplete Laravel validation rule builders. Create rules fluently without memorizing strings; each rule exposes only valid methods. Define nested array validation with each()/children(). Optional HasFluentRules trait speeds wildcard validation dramatically (up to 160x).

View on GitHub
Deep Wiki
Context7

Fluent validation rule builders for Laravel

Frequently asked questions about Laravel Fluent Validation
How does this package improve Laravel’s native validation rules?
It replaces string-based rules (e.g., `'required|string|min:2'`) with a fluent, type-safe API (e.g., `FluentRule::string()->required()->min(2)`). Each rule type only exposes relevant methods, reducing errors and enabling IDE autocompletion. Nested arrays are handled with `each()`/`children()`, keeping rules co-located instead of scattered across dot notation.
Will this break existing Laravel validation logic?
No—it’s designed as a drop-in replacement. Use the companion Rector package to automate migrations from string rules to fluent syntax. Start with non-critical validation (e.g., form requests) to test compatibility before full adoption.
Does it support Laravel’s `Rule::when()` or `Rule::unless()`?
Yes, but with a fluent twist. Use `when($condition, fn ($r) => $r->required())` or `unless($condition, fn ($r) => $r->string())` for conditional rules. The closure syntax ensures type safety and IDE hints for nested methods.
How does the `HasFluentRules` trait improve performance?
It optimizes wildcard validation (e.g., `items.*.id`) by reducing Laravel’s default O(n²) expansion to O(n) with batched processing. Benchmarks show up to 160x speedups for large arrays, ideal for bulk imports or API endpoints with deep nested validation.
Can I use custom validation logic with this package?
Yes, extend `FluentRule` or create custom rule builders. For dynamic rules, use closures: `FluentRule::custom(fn ($attr, $value) => YourCustomRule::validate($value))`. The package maintains compatibility with Laravel’s `Validator` extension methods.
What Laravel versions and PHP requirements does it support?
It requires **PHP 8.2+** and **Laravel 11+**. The modern PHP features (e.g., named arguments) enhance IDE support but aren’t mandatory for core functionality. Legacy projects may need a partial migration path.
How does testing work with fluent validation?
Test fluent rules like native Laravel validation. Use Pest or PHPUnit to assert rule chains: `FluentRule::string()->required()->min(2)->validate('test')` should throw an error. The package includes a `FluentRuleTestCase` helper for common assertions.
Are there alternatives to this package for fluent validation?
Laravel’s native validation is the baseline, but packages like `spatie/laravel-validation-rules` offer extensions. This package uniquely combines **type safety**, **IDE autocompletion**, and **performance optimizations** (e.g., `HasFluentRules`) not found in alternatives.
How do I handle nested arrays or multi-dimensional validation?
Use `each()` for flat arrays or `children()` for hierarchical data. Example: `FluentRule::array()->each(['id' => FluentRule::integer()->required()])`. For dynamic keys, combine with `when()` or `unless()` for conditional nesting.
What’s the learning curve for teams new to fluent APIs?
Minimal for Laravel devs—it mirrors Laravel’s existing validation patterns but removes string ambiguity. Start with simple rules (e.g., `FluentRule::string()->required()`) and gradually adopt `each()`/`children()` for complex cases. The Rector package automates bulk migrations.
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