What's Changed
Please read the upgrade guide for implications of this change.
Added
- Counter based codes for static codes set with
Vouchers::withCode(), so creating more than one voucher no longer collides:
Vouchers::withCounter()
Vouchers::withCounterStep()
Vouchers::withCounterSeparator()
Vouchers::withCounterPadding()
Vouchers::withoutCounterPadding()
Vouchers::withCodeFormatter() - New
FrittenKeeZ\Vouchers\CodeFormatvalue object passed to a custom code formatter, where casting to string yields the default formatting - New
FrittenKeeZ\Vouchers\Exceptions\CounterExceptionthrown when counter options are combined with a mask containing asterisks - New
Config::getCode()andConfig::hasCounterOptions()helpers - New
FrittenKeeZ\Vouchers\Casts\AsNullableArrayObjectcast, behaving like Laravel'sAsArrayObjectwhile preservingnullinstead of storing the JSON string'null' Vouchers::redeem(),Vouchers::unredeem(),Vouchers::redeemable()andVouchers::unredeemable()now accept aVoucherinstance in addition to a code, skipping the code lookup query- Added missing
unredeem()andunredeemable()methods to theVouchersfacade docblock
Optimization
Vouchers::batch()and counter code generation now check candidate codes against the database in as few queries as possible, instead of one query per code - creating 100 vouchers went from 100 lookups to 1, chunked at 500 codes per query
Fixed
Voucher::withOwner()andVoucherEntity::withEntity()now use the given instance's owngetMorphClass(), so they match rows written by a model overriding its morph type without a morph map entry
Changed
- Converted all model scopes from the
scopeXxx()prefix to the#[Illuminate\Database\Eloquent\Attributes\Scope]attribute - Metadata on
VoucherandRedeemeris now cast to an array object, so it can be mutated in place instead of being reassigned wholesale - Changed the published migration
metadatacolumns fromtexttojson- this only affects new installs, existing installs keeptextand continue to work - Modernised the published migration to use
$table->id()and$table->foreignId()->constrained()->cascadeOnDelete()- the resulting schema is unchanged, so no action is needed for existing installs - Trimmed redundant dev dependencies that only mirrored constraints already enforced by
laravel/frameworkandorchestra/testbench
Deprecated
- Dropped support for Laravel 11
- Dropped support for PEST 3
Breaking Changes
- Minimum supported Laravel version is now
12.4, where the#[Scope]attribute was introduced - Renamed the
Voucher::code()scope toVoucher::withCode()- a scope namedcodeshadows thecodecolumn and breaks$voucher->codewhen the attribute is not loaded - Scope methods are now
protectedinstead ofpublic- only relevant if you extend the models and override a scope - Renamed the first parameter of
Vouchers::redeem(),Vouchers::unredeem(),Vouchers::redeemable()andVouchers::unredeemable()from$codeto$voucher- only relevant if you call them using named arguments Voucher::$metadataandRedeemer::$metadatanow return anArrayObjectinstead of anarray, so code passing them to array functions must calltoArray()firstVouchers::withCode()combined with an amount greater than one now appends a counter instead of throwingInfiniteLoopException. UsingVouchers::withMask()with a static mask still throws as before
Full Changelog: 0.8.1...0.9.0