Overview
The Coupon System allows you to create various types of discount codes that customers can apply during checkout. Coupons support different discount types, date ranges, and usage tracking.Database Structure
Coupon Model
Location:app/Models/Coupon.php:1
Fillable Fields:
user_id- The admin user who created the coupontype- Coupon type (product_base, cart_base, welcome_base)code- Unique coupon codedetails- JSON field for additional configurationdiscount- Discount valuediscount_type- Either ‘percent’ or ‘amount’start_date- When coupon becomes validend_date- When coupon expires
user()- BelongsTo relationship with User model (app/Models/Coupon.php:13)userCoupons()- HasMany relationship tracking user-specific coupons (app/Models/Coupon.php:17)couponUsages()- HasMany relationship tracking coupon usage (app/Models/Coupon.php:22)
Coupon Types
Product-Based Coupons
Apply discounts to specific products. Configuration:- Select specific products
- Set discount amount or percentage
- Products are filtered by admin ownership
Cart-Based Coupons
Apply discounts to the entire shopping cart. Configuration:- Minimum order value (optional)
- Maximum discount cap (optional)
- Discount type (percentage or fixed amount)
Welcome-Based Coupons
Special coupons for new customers or first-time purchases. Configuration:- One-time use per customer
- Welcome discount amount
- Validity period
Creating Coupons
Configure Coupon Details
Fill in the required fields:
- Code: Unique coupon code (e.g., SUMMER2024)
- Discount Type: Percentage or Fixed Amount
- Discount Value: The discount amount
- Start Date: When the coupon becomes active
- End Date: When the coupon expires
Set Type-Specific Options
Depending on the coupon type, configure additional settings:
- Product-Based: Select applicable products
- Cart-Based: Set minimum cart value
- Welcome-Based: Configure first-purchase restrictions
Managing Coupons
Viewing Coupons
All coupons created by the admin are listed in the coupons index (app/Http/Controllers/CouponController.php:27-28):Editing Coupons
Location:app/Http/Controllers/CouponController.php:74-78
Coupon IDs are encrypted in the URL for security:
Updating Coupon Status
Location:app/Http/Controllers/CouponController.php:140-148
Toggle coupon active/inactive status without deleting:
Deleting Coupons
Location:app/Http/Controllers/CouponController.php:100-105
Permissions
The following permissions control access to coupon features (app/Http/Controllers/CouponController.php:12-18):view_all_coupons- View coupons listadd_coupon- Create new couponsedit_coupon- Modify existing couponsdelete_coupon- Remove coupons
Dynamic Form Loading
Create Forms
Location:app/Http/Controllers/CouponController.php:107-120
The system dynamically loads the appropriate form based on coupon type:
Edit Forms
Location:app/Http/Controllers/CouponController.php:122-138
Similar dynamic loading for edit forms with existing coupon data.
Validation
Coupons use theCouponRequest for validation (app/Http/Controllers/CouponController.php:47):
Usage Tracking
The Coupon model includes relationships for tracking usage:UserCoupons
Tracks which users have access to specific coupons:CouponUsages
Tracks when and how coupons are used:Best Practices
Coupon Code Naming:
- Use memorable, easy-to-type codes
- Avoid confusing characters (O vs 0, I vs l)
- Include context (e.g., SUMMER2024, NEWUSER15)
- Keep codes concise (8-12 characters recommended)
Example Use Cases
Seasonal Sale Coupon
- Type: Cart-Based
- Code: SUMMER2024
- Discount: 20% off
- Minimum: $50 cart value
- Duration: June 1 - August 31
Product Launch Promotion
- Type: Product-Based
- Code: NEWPRODUCT10
- Discount: $10 off
- Products: Specific new arrivals
- Duration: 2 weeks
New Customer Welcome
- Type: Welcome-Based
- Code: WELCOME15
- Discount: 15% off
- Usage: First purchase only
- Duration: 90 days