- How do I install sourcetoad/rule-helper-for-laravel?
- Install the package with Composer by running composer require sourcetoad/rule-helper-for-laravel. No configuration publishing or manual service provider registration is required for typical Laravel applications. Once installed, import either Sourcetoad\RuleHelper\RuleSet or Sourcetoad\RuleHelper\Rule in your Form Request or validator rules array.
- What is the difference between RuleSet and Rule in this package?
- RuleSet provides a fluent, chainable interface for building a complete rule array, so a single field's rules read top to bottom: required, unique, custom, max. Rule is a static helper class that mirrors Laravel's Illuminate\Validation\Rule facade but exposes the rest of Laravel's built-in rules as static methods like Rule::required() and Rule::max(255). Use RuleSet when you want readable chained rules, and Rule when you prefer array syntax consistent with Laravel's core Rule facade.
- Can I define a validation rule set once and reuse it across Form Requests?
- Yes. Call RuleSet::define with a name and a RuleSet instance inside your application service provider's boot method, for example a defined set named existing_email. Then apply it anywhere with RuleSet::useDefined('existing_email') and chain additional rules onto it. You can also merge a defined set into a new one with concatDefined, which keeps shared validation logic in one place instead of duplicating arrays.
- Does this package work with Laravel Form Requests, API validation, and Artisan commands?
- Yes. The package extends Laravel's Rule facade and Validator class, so it works anywhere Laravel validation is used: Form Requests, controller validation, API resource validation, and Artisan command input. Because the helpers are context-agnostic and only produce standard rule definitions, the surrounding validation layer does not change.
- How do requiredIfAll and requiredIfAny work?
- Both helpers accept multiple RequiredIf rules and combine them into one condition. requiredIfAll marks the field required only when every supplied RequiredIf rule evaluates to true. requiredIfAny marks the field required when at least one of the supplied RequiredIf rules evaluates to true, which is useful for conditional fields driven by several possible inputs.
- Which Laravel and PHP versions does rule-helper-for-laravel support?
- Support is defined by the composer.json constraints for php and illuminate/support on the release line you install, so check those values rather than assuming. The project moved from v6.3.0 to v7.0.0 and then v7.0.1, and a major bump may reset the supported Laravel and PHP matrix. Confirm the actual version ranges against the v7.0.0 changelog and composer constraints before pinning in production.
- Is there a base64 validation rule helper in this package?
- Version 7.0.1 adds a base64 rule helper alongside existing format and shape rules, aimed at API-first systems that receive encoded images, documents, or tokens from clients. Its exact semantics matter: strict versus lenient decoding, padding tolerance, whitespace and line-break handling, data-URI prefixes, and decoded size limits can differ from hand-rolled checks. Write characterization tests for any existing base64 validation before replacing it with the helper.
- How do I upgrade from v6.3 to v7 of rule-helper-for-laravel?
- Treat the upgrade as a planned migration rather than a routine composer update. Retrieve the v7.0.0 release notes plus the CHANGELOG and UPGRADING files to enumerate breaking changes, since the published v7.0.1 notes only describe the additive base64 helper. Verify whether helpers were renamed, signatures changed, or PHP and Laravel support was dropped, and check whether the custom rule extend pattern is affected.
- Does it support custom validation rules, unique with withoutTrashed, and other advanced rules?
- Yes. RuleSet includes a rule method for attaching custom rule instances, and helpers such as unique accept Laravel's advanced configuration closures, so you can call withoutTrashed on the Unique rule. This keeps custom and database-aware rules inside the same fluent definition instead of splitting them across arrays. Teams using domain-specific rules can also encapsulate business validation as reusable defined rule sets.
- Are there performance or security risks when validating base64 input with this package?
- Base64 validation can pull large encoded payloads into the request body, and decoding a multi-megabyte string in PHP can cause memory exhaustion or slow requests, especially before post_max_size enforcement applies. Pair the base64 helper with request size limits and a cap on decoded length, and prefer file uploads for large binaries. Otherwise the core rules add no significant overhead compared with equivalent Laravel validation.