NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

All exceptions live in RoundlyConsulting\Addresses\Exceptions and extend the abstract AddressesException (itself a RuntimeException), so you can catch the whole family with one type:

ExceptionThrown byMessage
IncompleteAddressExceptionPendingAddress::save() when city, street, postalCode or country is missing or blank.The address is missing required field(s): [street, country].
InvalidCountryExceptionAddressData::make() with normalise_country on, for anything that is not two or three letters.The value [XX1] is not a country code: expected two or three letters (ISO 3166-1 alpha-2 or alpha-3).
AddressOwnershipExceptionThe owner-checked writes — Addresses::for($owner)->setPrimary(), ->update() and ->delete(), and setPrimaryAddress() — with an address owned by another model, or an update that would move it to one. Nothing is written.The given address does not belong to this model.
TrashedAddressExceptionsetPrimary() or setPrimaryAddress() with a soft-deleted address, or Addresses::update() asking a soft-deleted address to become primary.A deleted address cannot be made primary; restore it first.
InvalidAddressTypeExceptionWriting a type not configured in addresses.types — AddressData (an explicit type, or default_type when none is given), the builder’s type(), createAddress(), assigning $address->type, AddressFactory::ofType() — and AddressTypes::resolve().The address type [foo] is not one of the configured address types (addresses.types).
AddressesExceptionAbstract base of all of the above; extends RuntimeException.—
InvalidConfigurationExceptionThe package toolkit’s exception, not an AddressesException — an unrecognised key_type when the migration runs, a malformed types list, a non-boolean normalise_country, a country_resolver that does not name a CountryResolver class, or a model that does not extend Address.Configuration value [addresses.country_resolver] must be a class-string of [RoundlyConsulting\Addresses\Contracts\CountryResolver], [App\Typo] given.
use RoundlyConsulting\Addresses\Exceptions\AddressesException;

try {
    $customer->newAddress()
        ->in($city)->at($street)->postalCode($postalCode)->country($country)
        ->save();
} catch (AddressesException $e) {
    // IncompleteAddressException, InvalidCountryException, …
    report($e);
}

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.