sylius/addressing
Sylius Addressing component provides models and services to manage addresses, countries, and provinces (states). Includes a flexible zones system to group regions and match addresses to zones—useful for shipping and tax calculations in PHP eCommerce apps.
spatie/laravel-doctrine-orm).symfony/validator) for address validation.CountryRepository, ProvinceRepository, ZoneMatcher, AddressValidator.Country, Province, Address, Zone (with ZoneMember for hierarchical grouping).| Risk Area | Severity | Mitigation |
|---|---|---|
| Schema Migrations | High | Requires careful handling of existing address tables; use factories or data mappers for legacy data. |
| Zone Logic Complexity | Medium | Zones use rule-based matching (e.g., "all countries except X"). Test edge cases (e.g., overlapping zones). |
| Validation Overhead | Low | Optional; can be bypassed if using custom validation (e.g., third-party APIs). |
| Performance | Low | Zone matching is O(n) for addresses; optimize with caching (e.g., Redis) for frequent queries. |
| Testing | Medium | Limited built-in tests; mock zones and addresses in unit/integration tests. |
Address entities? Will you need a hybrid model?Address tables with Sylius entities (e.g., sylius/addressing:install --orm=eloquent).AppServiceProvider:
$this->app->bind(CountryRepositoryInterface::class, CountryRepository::class);
use Sylius\Component\Addressing\Validator\Constraints\ValidCountry;
addresses table → sylius_address).Schema::create('sylius_addresses', function (Blueprint $table) {
$table->id();
$table->string('street');
$table->string('city')->nullable();
$table->foreignId('country_code')->constrained('sylius_countries');
// ... other fields
});
LegacyAddressMapper).class LegacyAddressMapper
{
public function toSylius(array $legacyData): Address
{
return new Address(
street: $legacyData['street'],
city: $legacyData['city'] ?? null,
countryCode: $legacyData['country_code']
);
}
}
zoneMatcher->match($address)).symfony/validator v5.x manually.Country, Province, Address entities.ZoneMatcher into shipping/tax logic.ResourceInterface) may feel heavy for simple use cases.ZoneMatcher::match($address) to debug why an address isn’t in a zone.AddressValidator constraints for failed rules.sylius_* table prefixes) may require adherence.How can I help you explore Laravel packages today?