ricadesign / laravel-coupon
Laravel Coupon
Requires
- laravel/framework: ^9.0|^8.0 | ^7.0 | ^6.0 | ^5.0
This package is auto-updated.
Last update: 2025-03-07 15:13:00 UTC
README
This composer package offers a setup to redeem coupon codes on ecommerce sites. It enables the use of several types of discounts, while offering the possibility of limiting user redemption by different means.
Installation
Begin by pulling in the package through Composer.
composer require ricadesign/laravel-coupon
Next, if using Laravel 5, include the service provider within your config/app.php
file. From version 5.5 and thanks to package autodiscovery this is no longer necesary.
'providers' => [ Ricadesign\LaravelCoupon\LaravelCouponServiceProvider::class, ];
Publishing migrations
In order for the package to work, the migrations included need to be published with the following command:
php artisan vendor:publish
Then you can run them with:
php artisan migrate
Usage
Once installed a registered user will be able to send a GET petition to /coupon?discount={COUPON_CODE}. Either a valid coupon or a 404 error response will be returned.
The RicaDesign\LaravelCoupon\Coupon model also provides the following methods:
Method | Params | Returns | Description |
---|---|---|---|
static findAndValidate | couponCode, subtotal, itemsCount | A valid coupon model or null | |
getDiscount | subtotal | Amount to be subtracted from subtotal (positive) | |
use | userId | void | Increments times_used field, adds entry to user_coupon table (if needed) |
Coupon properties
Property | Description |
---|---|
value_discount | Value to discount in coupon type FixPrice |
code_name | Codigo de descuento |