- How do I install laravel-validation-rules/us-state in a Laravel app?
- Install it with Composer using composer require laravel-validation-rules/us-state. The package supports Laravel package auto-discovery, so no manual service provider registration is typically required. After installing, reference the provided rule in your validation rules array, FormRequest, or inline validator call and add tests for the state formats you accept.
- Does this package support Laravel 12?
- Yes. Release 1.9.0 was assessed as adding Laravel 12.x compatibility, making it viable for teams running or upgrading to Laravel 12. If you are on Laravel 10 or 11, check the composer.json constraints for the exact version range before upgrading, since the release is described as compatibility maintenance rather than a breaking change. Confirm the supported matrix in CI or a non-production branch before rolling it out broadly.
- What PHP version does laravel-validation-rules/us-state require?
- The exact PHP constraint is defined in the package's composer.json, so verify it there before adopting. Because Laravel 12 generally implies PHP 8.2 or newer, confirm your runtime aligns with both the framework and the package requirements. Running composer why-not or a dry-run update is a quick way to catch mismatches.
- Does the rule validate state abbreviations, full state names, or both?
- The package is designed to validate US state input such as state names, abbreviations, and codes, but you should confirm which formats the specific rule you use accepts. Some rules are strict about two-letter codes while others accept full names, so pick the one that matches your form field. Document the accepted formats for product and support teams to avoid false rejections.
- Are Washington DC and US territories included in the state list?
- Coverage of DC and territories such as Puerto Rico or Guam depends on the rule implementation, and the assessed risks explicitly flag this as something to verify. Before rolling out, write tests asserting that every value your business needs is accepted, including DC if you ship there. If a required territory is missing, you can extend validation with your own rule alongside the package.
- Does this package also validate Canada provinces?
- Yes, the package description covers validating US states and Canada provinces. That makes it useful for North American billing and shipping address forms in a single dependency. As with US states, test the exact province formats your checkout accepts, including abbreviations versus full names.
- Can I customize the validation error message returned for an invalid state?
- Laravel lets you override rule messages by passing a custom message as the third argument to the rule in your rules array, or by defining messages in a FormRequest. Whether the package exposes configurable messages directly should be confirmed in its documentation. Either way, you can surface a friendly message like "Please select a valid US state" rather than a generic failure.
- Can I use this rule in FormRequests and API request validation?
- Yes. It is a standard Laravel validation rule, so it works anywhere the validator runs, including FormRequests, inline Validator::make calls, and API request classes. A common adoption path is to introduce it on one high-value form or endpoint, add acceptance tests, then expand to other address surfaces. It keeps address validation at the domain input layer without maintaining your own state list.
- How does this compare to a custom regex or an in: rule with a hardcoded state list?
- A custom regex or an in: list works, but you own the maintenance: adding territories, fixing misspellings, and keeping names and abbreviations consistent. This package centralizes that list in a small, focused dependency that fits the Laravel validation pipeline. The tradeoff is an extra Composer dependency, so verify its Laravel and PHP constraints match your application.
- Is laravel-validation-rules/us-state a replacement for full postal address verification?
- No. It validates the state field only and should be positioned as state-field validation and normalization support, not as an address verification service. It makes no external calls and adds no runtime infrastructure, so it cannot confirm that an address is deliverable. Pair it with a proper address verification provider if you need that level of assurance.