All packages
Advertisements for Laravel
Exceptions
The package’s own errors extend RoundlyConsulting\Advertisements\Exceptions\AdvertisementException. Prices, slugs and config are validated by the sibling packages, which throw their own typed exceptions:
| Exception | When |
|---|---|
AdvertisementException | Base class for the package’s own errors (a RuntimeException) — catch the whole surface with one type. |
InvalidTargeting | A value other than a Targeting or null assigned to targeting. |
AdvertisementNotActive | for($ad)->track() on an ad that isn’t live right now — a draft, scheduled, expired or archived ad credits nothing. |
AdvertisementNotInPlacement | for($ad)->track($placement) with a placement the ad doesn’t run in — a forged or stale click URL can’t credit a zone. |
InvalidMoneyValue | Anything but Money|null assigned to price, or an amount wider than int64 on SQLite (money-for-laravel). |
CurrencyMismatch | A price in another currency assigned to a priced ad — set currency first (money-for-laravel). |
RoundingNecessary | fromDecimal() with more decimals than the currency allows (money-for-laravel). |
SlugAlreadyTakenException | A manual placement or category slug that’s already taken (sluggable-for-laravel). |
InvalidConfigurationException | A config value of the wrong shape, naming the key: a model key that isn’t the packaged model or a subclass, an unrecognised key_type, bool or match_when_unknown value, a string setting set to a non-string, or a bad or blank responsive width (package-toolkit-for-laravel). |
InvalidArgumentException | media.text_ad_view names a view that doesn’t exist. |
use RoundlyConsulting\Advertisements\DataTransferObjects\AdvertisementData;
use RoundlyConsulting\Advertisements\Exceptions\AdvertisementException;
use RoundlyConsulting\Advertisements\Models\Placement;
use RoundlyConsulting\Money\Exceptions\MoneyException;
use RoundlyConsulting\Sluggable\Exceptions\SlugAlreadyTakenException;
try {
$ad->targeting = ['countries' => ['SK']]; // not a Targeting instance
} catch (AdvertisementException $e) {
// InvalidTargeting — one catch covers the package's own errors
}
try {
AdvertisementData::fromDecimal(name: 'Bike', amount: '19.999'); // finer than a cent
} catch (MoneyException $e) {
// RoundingNecessary — money's errors share the MoneyException base
}
try {
Placement::query()->create(['name' => ['en' => 'Sidebar'], 'slug' => 'sidebar']);
} catch (SlugAlreadyTakenException $e) {
// a manual placement/category slug is never silently suffixed
}Money exceptions extend RoundlyConsulting\Money\Exceptions\MoneyException; SlugAlreadyTakenException lives in RoundlyConsulting\Sluggable\Exceptions and InvalidConfigurationException in RoundlyConsulting\PackageToolkit\Exceptions.
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.