axlon/laravel-postal-code-validation
Illuminate\Validation\Rule), making it a natural fit for form/input validation workflows. It extends Laravel’s existing rule-based validation (e.g., Rule::unique(), Rule::required()), reducing architectural disruption.app/Http/Requests/*).Validate middleware).| Risk Area | Mitigation Strategy |
|---|---|
| Google ADS Dependency | Implement a local fallback (e.g., static JSON rule sets) for offline use. |
| API Latency | Cache responses (e.g., Redis) for frequent validations or batch requests. |
| Country-Specific Rules | Test edge cases (e.g., military addresses, PO boxes) with real-world data. |
| Version Lock-in | Monitor Laravel 10+ compatibility; package may lag behind major Laravel updates. |
| Rate Limiting | Set up request throttling or queue delayed validations for bulk submissions. |
POST /orders).StoreOrderRequest).PostalCode::rule().use Axlon\PostalCodeValidation\Rules\PostalCode;
public function rules()
{
return [
'shipping_address.postal_code' => [
'required',
PostalCode::rule()->country('US'), // or 'country' => 'CA'
],
];
}
config/postal-code-rules.php) for offline use.PostalCode::rule()->fallback([
'US' => ['^[0-9]{5}(?:-[0-9]{4})?$'],
'CA' => ['^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$'],
]);
| Component | Compatibility Notes |
|---|---|
| Laravel 5.5–10.x | Tested; minor version bumps may require adjustments (e.g., Rule class changes). |
| Lumen | Supported; follow same installation steps. |
| Custom Validation | Works with Laravel’s Validator facade and FormRequest classes. |
| Third-Party Packages | No known conflicts; validate against laravel-address, spatie/laravel-geo if used. |
| PHP 7.2–8.2 | Compatible; ensure google/apiclient (dependency) aligns with your PHP version. |
PostalCode::rule().street_number, city).google/apiclient for breaking changes (ADS API updates).config/postal-code-overrides.php).try {
$validator->validate([...]);
} catch (\Google\ApiCore\ApiException $e) {
\Log::error("ADS Validation Failed: " . $e->getMessage());
// Fallback to local rules
}
resources/lang/en/validation.php).Illuminate\Cache):
$cacheKey = "postal_code_rules_{$country}";
$rules = \Cache::remember($cacheKey, now()->addHours(24), function () use ($country) {
return PostalCode::rule()->country($country)->getRules();
});
throttle middleware or a queue system.foreach ($addresses as $address) {
PostalCodeValidationJob::dispatch($address)->delay(now()->addSeconds(5));
}
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| ADS API Outage | Validation fails silently. | Fallback to local rule |
How can I help you explore Laravel packages today?