---
title: "Custom models — Advertisements for Laravel | Roundly"
description: "Point the four model config keys at your own subclasses to add fields and logic while keeping every scope, relation and cast."
url: https://roundly-consulting.com/open-source/docs/advertisements-for-laravel/custom-models
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Advertisements for Laravel](https://roundly-consulting.com/open-source/docs/advertisements-for-laravel.md)

# Custom models

The package resolves every model through config — model, placement\_model, category\_model and event\_model. Extend the packaged class, keep its table and register it:

```php
namespace App\Models;

use RoundlyConsulting\Advertisements\Models\Advertisement;

class Listing extends Advertisement
{
    protected $table = 'advertisements';   // keep the package table

    public function isFeatured(): bool
    {
        return (bool) $this->meta?->get('featured');
    }
}
```

```php
// config/advertisements.php
'model' => App\Models\Listing::class,
'placement_model' => RoundlyConsulting\Advertisements\Models\Placement::class,
'category_model' => RoundlyConsulting\Advertisements\Models\Category::class,
'event_model' => RoundlyConsulting\Advertisements\Models\AdvertisementEvent::class,
```

- The packaged models aren’t final for exactly this. Extend them — the scopes, casts, relations, slugs and creative buckets come along.
- Set $table when your class name differs from the package’s (Listing would otherwise look for listings).
- A config value that isn’t the packaged model or a subclass of it — not an Eloquent model at all, or an unrelated one — throws InvalidConfigurationException naming the key; it is never silently replaced by the packaged model.
- Relations name their pivot table and foreign keys explicitly, so a subclass still reads advertisement\_placement and advertisement\_id.
- Everything the package creates or queries — the facade, actions, resolvers, scopes and the tracking job — goes through the configured classes. Type-hint your subclass in routes to bind it.

## 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/advertisements-for-laravel.md)
