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
Rule Helper For Laravel

Rule Helper For Laravel Laravel Package

sourcetoad/rule-helper-for-laravel

Fluent helpers for building Laravel validation rules. Use RuleSet to chain required/unique/max and add custom rules, or Rule for static rule builders. Supports reusable defined rule sets and extras like requiredIfAll/requiredIfAny for complex conditions.

View on GitHub
Deep Wiki
Context7

Rule Helper

Frequently asked questions about Rule Helper For Laravel
How does this package improve Laravel’s built-in validation rules?
It adds fluent helper methods like `RuleSet::create()` and `Rule::required()` to reduce boilerplate in Form Requests. For example, `RuleSet::create()->required()->max(255)` replaces verbose array syntax. It also includes domain-specific helpers (e.g., `betweenDates()`) for cleaner business logic.
Can I use this with Laravel 10+ and PHP 8.2+?
Yes, the package is designed for Laravel 10+ and requires PHP 8.2+. Check the GitHub repo for updates if you’re using newer Laravel versions (e.g., 11+). Always verify compatibility with your stack before integrating.
How do I define reusable rule sets across my app?
Use `RuleSet::define()` in your `AppServiceProvider` to create named rule sets (e.g., `RuleSet::define('existing_email', RuleSet::create()->email()->exists('users'))`). Then reuse them with `RuleSet::useDefined('existing_email')` in Form Requests.
Does this work with Laravel’s Form Requests and API validation?
Absolutely. The package integrates seamlessly with Form Requests (e.g., `rules()` method) and API validation pipelines. Replace array-based rules with fluent syntax like `Rule::required()` or `RuleSet::create()->unique()->max(255)` for cleaner code.
What’s the performance impact of using custom rule helpers?
Minimal for most use cases, but regex-heavy or complex rules (e.g., `isValidCreditCard()`) could introduce slight latency. Test critical paths in staging. The package avoids global overhead by design—only use helpers for truly reusable logic.
How do I test custom rules added via `RuleHelper::extend()`?
Use Laravel’s `Validator::make()` with `RuleHelper` methods in unit tests. For example, test `RuleHelper::betweenDates()` with `Validator::make(['date' => '2023-01-01'], ['date' => RuleHelper::betweenDates('2020-01-01', '2024-01-01')])->fails()`. PestPHP assertions work well for this.
Can I migrate existing validation logic to this package?
Yes. Start with non-critical rules (e.g., `RuleHelper::isValidEmail()`) in a pilot feature. Replace duplicated logic in controllers/FormRequests with `RuleSet::create()` or `Rule::required()`. Update tests to reflect the new syntax.
What are the alternatives to this package?
Laravel’s native `Rule::custom()` or `Rule::make()` can handle simple cases, but they lack reusable helpers. For lightweight needs, a custom trait or helper class might suffice. This package excels for teams with complex, repeated validation logic (e.g., DDD domains).
How do I handle locale-specific validations (e.g., phone numbers)?
Use Laravel’s built-in `regex` rules or extend `RuleHelper` with custom methods. For example, `RuleHelper::define('validPhoneUS', Rule::regex('/^\+?1?[0-9]{10}$/'))`. Document locale-specific rules in a `VALIDATION_RULES.md` file for consistency.
Is this package actively maintained? How do I check?
Check the GitHub repository for recent commits, open issues, and release frequency. The package is MIT-licensed and designed for Laravel 10+, but active maintenance depends on the author’s updates. Look for responses to issues or pull requests as a sign of ongoing support.
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