---
title: "Extending — Coupons for Laravel | Roundly"
description: "Swap in your own Coupon subclass via coupons.model and reuse the eligibility guard in custom checkout flows."
url: https://roundly-consulting.com/open-source/docs/coupons-for-laravel/extending
language: en
---

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

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

# Extending

## A custom coupon model

Subclass Coupon and point coupons.model at it. Every manager, action and rule query, both Artisan commands, a redemption’s coupon relation and Coupons::fake() go through it:

```php
namespace App\Models;

use RoundlyConsulting\Coupons\Models\Coupon;

class ShopCoupon extends Coupon
{
    protected $table = 'coupons';

    // your own relations, scopes, accessors and model events
}
```

```php
// config/coupons.php
'model' => App\Models\ShopCoupon::class,
```

- Set $table = 'coupons' when your class name differs — Eloquent would otherwise derive the table from the class name. The redemptions relation keys on coupon\_id explicitly, so any class name works.
- A value that isn’t Coupon or a subclass of it throws the toolkit’s InvalidConfigurationException naming the key — it is never silently replaced by the packaged model.
- CouponRedemption is final and isn’t swappable.

## Reusing the eligibility guard

For most flows Coupons::check() is enough — it returns the first failing reason through the facade, and the fake sees it. Underneath, RedemptionGuard is the single source of truth for eligibility. firstFailure() returns the first failing RedemptionFailureReason — or null — without throwing; a soft-deleted coupon reports NotFound first, and a null price skips the currency and minimum-spend checks. throwFor() raises the matching exception, CouponNotFound included:

```php
use RoundlyConsulting\Coupons\Support\RedemptionGuard;

$guard = app(RedemptionGuard::class);

$reason = $guard->firstFailure($coupon, $cartTotal, $user);   // ?RedemptionFailureReason — never throws

if ($reason !== null) {
    $message = __($reason->translationKey(), ['code' => $coupon->code]);   // customer-facing text

    $guard->throwFor($coupon, $reason, $cartTotal);                       // or raise the matching exception
}
```

## Other hooks

- Events — analytics, fraud checks, sold-out notices and audit logs on the five events.
- Translations — English and Slovak ship; publish coupons-translations to reword them or add another language.
- UUID or ULID redeemers — set coupons.key\_type before migrating.

## 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/coupons-for-laravel.md)
