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

Database schema

Both tables come from the published migrations. Money columns are money-for-laravel decimal(38,0) minor-unit columns that share one currency column per row.

coupons

ColumnTypeNotes
idbigint PK
typestringDefault fixed.
valuebigintMinor units (Fixed) or basis points (Percentage).
codestring, indexedStored trimmed and upper-cased.
usageintegerDefault 0.
max_usageintegerDefault 0 = unlimited.
max_usage_per_redeemerunsigned integerDefault 0 = unlimited.
currencycurrencyCode, nullableThe currency lock.
minimum_spendmoney, nullableShares currency.
max_discountmoney, nullableShares currency.
activated_attimestamp, nullableNull = not yet active.
expires_attimestamp, nullableNull = no expiry.
metajsonb, nullableCast to a collection.
created_at, updated_at, deleted_attimestampsSoft deletes.
undeleted_codestring, nullable, stored generated, uniqueMirrors code while the row isn’t trashed and is null once it is, so codes stay unique among live coupons. Hidden from arrays and JSON.

coupon_redemptions

ColumnTypeNotes
idbigint PK
coupon_idforeignId → coupons.idCascade on delete.
redeemer_type, redeemer_idmorphKey, nullableKey type from coupons.key_type; null for guest redemptions.
amount_discounted, currencymoneyThe recorded discount.
created_at, updated_at, deleted_attimestampsSoft deletes.

code is indexed, not unique: uniqueness among live coupons comes from the unique index on the generated undeleted_code column, so a soft-deleted coupon’s code can be issued again. That needs MySQL/MariaDB, PostgreSQL or SQLite — SQL Server’s unique indexes treat NULLs as equal. The model leaves undeleted_code out of replicate().

On SQLite, money’s cast refuses amounts beyond int64 (InvalidMoneyValue).

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.