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
| Column | Type | Notes |
|---|---|---|
id | bigint PK | |
type | string | Default fixed. |
value | bigint | Minor units (Fixed) or basis points (Percentage). |
code | string, indexed | Stored trimmed and upper-cased. |
usage | integer | Default 0. |
max_usage | integer | Default 0 = unlimited. |
max_usage_per_redeemer | unsigned integer | Default 0 = unlimited. |
currency | currencyCode, nullable | The currency lock. |
minimum_spend | money, nullable | Shares currency. |
max_discount | money, nullable | Shares currency. |
activated_at | timestamp, nullable | Null = not yet active. |
expires_at | timestamp, nullable | Null = no expiry. |
meta | jsonb, nullable | Cast to a collection. |
created_at, updated_at, deleted_at | timestamps | Soft deletes. |
undeleted_code | string, nullable, stored generated, unique | Mirrors 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
| Column | Type | Notes |
|---|---|---|
id | bigint PK | |
coupon_id | foreignId → coupons.id | Cascade on delete. |
redeemer_type, redeemer_id | morphKey, nullable | Key type from coupons.key_type; null for guest redemptions. |
amount_discounted, currency | money | The recorded discount. |
created_at, updated_at, deleted_at | timestamps | Soft 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 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.