Configuration
The package ships sensible defaults and works with zero configuration. The published config/coupons.php in full:
use RoundlyConsulting\Coupons\Models\Coupon;
return [
'model' => Coupon::class,
// Key type of the polymorphic redeemer column: "bigint", "uuid" or "ulid".
'key_type' => env('COUPONS_KEY_TYPE', 'bigint'),
'default_currency' => env('COUPONS_CURRENCY', 'USD'),
'redeemer' => [
'track' => env('COUPONS_TRACK_REDEEMERS', true),
],
'code' => [
'length' => env('COUPONS_CODE_LENGTH', 6),
'charset' => env('COUPONS_CODE_CHARSET', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),
],
'route_key' => env('COUPONS_ROUTE_KEY', 'code'),
];Every key
| Key | Type | Default | Env | Purpose |
|---|---|---|---|---|
model | class-string | Coupon::class | — | The coupon model. Point it at a subclass of the package Coupon; anything else throws InvalidConfigurationException naming the key. The manager, actions, rule and both commands use it. |
key_type | string | bigint | COUPONS_KEY_TYPE | Key type of the polymorphic redeemer column on coupon_redemptions: bigint, uuid or ulid. Read by the migration — set it before migrating. Anything else throws InvalidConfigurationException naming the key. |
default_currency | string | USD | COUPONS_CURRENCY | ISO 4217 code the shipped CouponFactory locks fixed and capped coupons to when a state names none; also shown by about. Redemption never assumes a currency — it always takes the cart total’s. A blank value (COUPONS_CURRENCY=) is not set, so USD applies; a non-string value throws InvalidCouponConfiguration naming the key. |
redeemer.track | bool | true | COUPONS_TRACK_REDEEMERS | Write a coupon_redemptions row for every redemption that has a redeemer — powers per-redeemer caps, usageBy() and hasRedeemed(). Env-style values work: 1/true/on/yes and 0/false/off/no; a blank value is not set, so tracking stays on; anything else throws InvalidConfigurationException naming the key. |
code.length | int | 6 | COUPONS_CODE_LENGTH | Length of auto-generated codes, 4–64. An integer string such as “8” works; a blank value is not set, so 6 applies; “eight” or “8.5” throws. |
code.charset | string | A–Z 0–9 | COUPONS_CODE_CHARSET | Alphabet for generated codes: at least 2 distinct symbols (case-insensitively), no whitespace or control characters. It’s upper-cased like every code; multibyte symbols are fine. A blank value is not set, so A–Z 0–9 applies. |
route_key | string | code | COUPONS_ROUTE_KEY | Column used for route-model binding of {coupon}. Set it to id to bind by primary key. A blank value is not set, so code applies; a non-string value throws InvalidCouponConfiguration naming the key rather than binding by code. |
Environment
Every key except model is env-backed, so you rarely need to publish the config at all:
COUPONS_KEY_TYPE=bigint
COUPONS_CURRENCY=EUR
COUPONS_TRACK_REDEEMERS=true
COUPONS_CODE_LENGTH=8
COUPONS_CODE_CHARSET=ABCDEFGHJKLMNPQRSTUVWXYZ23456789
COUPONS_ROUTE_KEY=codeCOUPONS_TRACK_REDEEMERS takes env-style values: 1, true, on or yes keep tracking on; 0, false, off or no switch it off; a blank value (COUPONS_TRACK_REDEEMERS=) is not set, so tracking stays on. Anything else throws InvalidConfigurationException naming the key.
A key you remove, set to null or leave blank (COUPONS_CURRENCY=) is not set and takes its default; a key you set to a value of the wrong shape throws instead of falling back, and php artisan about shows a broken route_key, default_currency or code.* value as INVALID, with the reason. An unusable code.length or code.charset throws InvalidCouponConfiguration the moment a code is generated — see Generated codes; a non-string route_key or default_currency throws it when read. key_type is read only when the migration runs.
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.