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

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:

ExceptionWhen
AdvertisementExceptionBase class for the package’s own errors (a RuntimeException) — catch the whole surface with one type.
InvalidTargetingA value other than a Targeting or null assigned to targeting.
AdvertisementNotActivefor($ad)->track() on an ad that isn’t live right now — a draft, scheduled, expired or archived ad credits nothing.
AdvertisementNotInPlacementfor($ad)->track($placement) with a placement the ad doesn’t run in — a forged or stale click URL can’t credit a zone.
InvalidMoneyValueAnything but Money|null assigned to price, or an amount wider than int64 on SQLite (money-for-laravel).
CurrencyMismatchA price in another currency assigned to a priced ad — set currency first (money-for-laravel).
RoundingNecessaryfromDecimal() with more decimals than the currency allows (money-for-laravel).
SlugAlreadyTakenExceptionA manual placement or category slug that’s already taken (sluggable-for-laravel).
InvalidConfigurationExceptionA 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).
InvalidArgumentExceptionmedia.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 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.