Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Couponables

Laravel Couponables Laravel Package

michael-rubel/laravel-couponables

Laravel Couponables adds coupon and voucher support to any Eloquent model. Create redeemable codes, attach them polymorphically to users or orders, and enforce usage limits, expiry dates, and per-model redemption rules through a clean, extensible API.

View on GitHub
Deep Wiki
Context7

This package provides polymorphic coupon functionality for your Laravel application.

Frequently asked questions about Laravel Couponables
How do I install and set up laravel-couponables in a Laravel application?
Run composer require michael-rubel/laravel-couponables, then publish the package config and migrations with php artisan vendor:publish and run php artisan migrate. Add the Couponable trait to the models that should redeem coupons, such as your User and Order models. There are no external services, queues, or scheduled jobs to configure, so setup takes only a few minutes.
Which Laravel versions does this coupon package support?
The 9.0.2 release added Laravel 12 support, so the package follows the modern Laravel release cycle. Because it is a small single-maintainer project, check the composer.json constraint and CI matrix before adopting it on an older Laravel version. Pin a specific release you have actually tested if you are on an older branch.
Can I attach coupons to models other than User, like Order or Cart?
Yes. The package is built around a polymorphic redemption relationship, so any Eloquent model such as Order, Cart, or GuestSession becomes couponable once the trait is added. This decouples who consumed the coupon from what the coupon is, which suits teams recording redemption against a user and an order at the same time. Register a morph map so stored morph types stay stable if you rename classes.
Does laravel-couponables support percentage and fixed amount discounts?
The coupon entity carries a type and value, covering percentage and fixed-amount discounts, alongside expiry dates and usage limits. It is not a promotions engine: stacking, priority or conflict resolution, product or category targeting, BOGO, tiered discounts, and multi-currency rules must be built on top of or instead of the package. Set that scope expectation with stakeholders before the project starts.
How are coupon usage limits enforced in this package?
Limits live on the Coupon model and are checked when a coupon is validated and redeemed, with guard exceptions thrown for expired, exhausted, or invalid redemptions. The package offers configurable limits, but confirm in a spike whether a given rule is global or scoped per couponable model in your version. If a per-user limit must hold when both a User and an Order redeem, plan your own scoping logic on top.
Is redemption limit enforcement safe under concurrent requests?
Not automatically. With a read-then-write pattern, two simultaneous requests against a coupon with one redemption remaining can both pass the check and both redeem it. Wrap validation and redemption in the same database transaction as your order write, and make the check atomic with lockForUpdate, a unique constraint, or a conditional update. Test this explicitly with parallel requests during your spike.
How do I handle refunds and cancellations, and can I un-redeem a coupon?
There is no obvious first-class reversal or void, so refunds and cancellations mean deleting the redemption record yourself or building an internal reversal service. Plan this before launch, because finance-visible defects usually surface here first. Also watch percentage rounding on decimal totals and timezone boundaries on expires_at, the other classic edge cases.
Can I replace the package's Coupon and redemption models with my own?
Yes, model swap-outs are config-driven, so you can point the package at your own Coupon and redemption models when you need extra fields, UUID or ULID keys, soft deletes, or multi-tenant scoping. Keep your subclasses compatible with the package contracts and re-run the package tests after swapping. This also isolates your code from upstream changes.
How should I test coupon redemption in my Laravel application?
Use RefreshDatabase with the published migrations and write feature tests around the two natural seams: a read-only validation step and a write step that consumes the coupon inside the order transaction. Assert that the guard exceptions for expired, exhausted, and invalid coupons map to the correct user-facing messages. Because the install base is small, your own suite is the main safety net, so include a concurrency test.
Is laravel-couponables actively maintained, and what are the alternatives?
It is actively released, with 9.0.2 confirming maintenance through the Laravel 12 cycle, but it is a single-author MIT project with roughly 200 stars and effectively no listed dependents, so bus factor is one. Pin the version and wrap it behind a thin internal adapter if you depend on it long term. If you need a full promotions engine with stacking and eligibility rules, evaluate dedicated promotion packages or build the rules layer yourself rather than stretching this one.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect