- 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.