All packages
Addresses for Laravel
Exceptions
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:
| Exception | Thrown by | Message |
|---|---|---|
IncompleteAddressException | PendingAddress::save() when city, street, postalCode or country is missing or blank. | The address is missing required field(s): [street, country]. |
InvalidCountryException | AddressData::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). |
AddressOwnershipException | Addresses::for($owner)->setPrimary() or setPrimaryAddress() with an address owned by another model. | The given address does not belong to this model. |
TrashedAddressException | setPrimary() 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. |
InvalidAddressTypeException | Building an address without a type while default_type is not an AddressType value — and your own code that converts untrusted strings. | The address type [foo] is not a valid AddressType. |
AddressesException | Abstract base of all of the above; extends RuntimeException. | — |
InvalidConfigurationException | The package toolkit’s exception, not an AddressesException — an unrecognised key_type when the migration runs, 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 cryptoBy 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.