PHPackages                             pixellair/laravel-discount-system - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pixellair/laravel-discount-system

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pixellair/laravel-discount-system
=================================

Laravel discount system

v1.0.0(11mo ago)35MITPHPPHP ^8.0

Since Jun 16Pushed 10mo agoCompare

[ Source](https://github.com/pixellair/laravel-discount-system)[ Packagist](https://packagist.org/packages/pixellair/laravel-discount-system)[ RSS](/packages/pixellair-laravel-discount-system/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

🎟️ Laravel Discount System
==========================

[](#️-laravel-discount-system)

A reusable, Composer-installable **coupon-based discount system** for Laravel projects.

Easily integrates into any Laravel app to provide:

- 🎯 Percentage or fixed amount discounts
- ⏳ Time-limited discounts
- 🔂 One-time use or limited usage
- 👤 Per-user restrictions (only once per user)
- 👥 Coupons for specific users only
- 💵 Minimum order amount validation
- 🧠 Smart code generation with type prefixes

---

🚀 Installation
--------------

[](#-installation)

### 1. Require via Composer

[](#1-require-via-composer)

```
composer require pixellair/laravel-discount-system

```

### 2. Publish and Run Migrations

[](#2-publish-and-run-migrations)

To create the necessary tables for storing discounts and their usage:

```
php artisan vendor:publish --tag=laravel-discount-system-migrations
php artisan migrate
```

### 🔧 Setup (If Needed)

[](#-setup-if-needed)

If you're using Laravel 8+ with package auto-discovery, no setup is needed.

If not, register the service provider manually in config/app.php:

```
'providers' => [
    DiscountSystem\DiscountSystemServiceProvider::class,
],
```

\###⚙️ Usage Apply a Coupon to an Order

```
use DiscountSystem\Services\DiscountService;

$service = new DiscountService();

$result = $service->apply($couponCode, $userId, $orderAmount);

$discountAmount = $result['amount'];
$discount = $result['discount'];
```

Record a Usage After Applying

```
$service->recordUsage($discount, $userId);
```

### 🧪 Validations Performed in apply()

[](#-validations-performed-in-apply)

✅ Coupon exists

⏳ Coupon is active (start &amp; end time)

🔂 Usage limit not exceeded

👤 Coupon not already used by this user (if once\_per\_user)

👥 User is in allowed list (if specific\_user\_ids set)

💵 Order meets min\_order\_amount requirement

If any condition fails, a ValidationException is thrown with a meaningful message.

🧾 Code Generation Generate a prefixed coupon code for any type:

```
$code = $discountService->generateCode('T'); // e.g., T7K92LA
```

The prefix lets you categorize discounts (e.g., T for time-limited, A for amount-based).

💡 Example Controller Usage

```
use DiscountSystem\Services\DiscountService;

public function applyCoupon(Request $request)
{
    $service = new DiscountService();

    try {
        $result = $service->apply($request->code, auth()->id(), $order->total);

        $order->discount_amount = $result['amount'];
        $order->save();

        $service->recordUsage($result['discount'], auth()->id());

        return response()->json(['success' => true, 'discount' => $result['amount']]);
    } catch (\Illuminate\Validation\ValidationException $e) {
        return response()->json(['error' => $e->getMessage()], 422);
    }
}
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance52

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

331d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e91683ab666e3675c9d6f6563e1b29401aa19c356a4e5e6691e3439174615c1a?d=identicon)[ahmadaskari48](/maintainers/ahmadaskari48)

---

Top Contributors

[![ahmadaskari48](https://avatars.githubusercontent.com/u/84067785?v=4)](https://github.com/ahmadaskari48 "ahmadaskari48 (9 commits)")[![ahmadaskariG](https://avatars.githubusercontent.com/u/251128527?v=4)](https://github.com/ahmadaskariG "ahmadaskariG (2 commits)")

### Embed Badge

![Health badge](/badges/pixellair-laravel-discount-system/health.svg)

```
[![Health](https://phpackages.com/badges/pixellair-laravel-discount-system/health.svg)](https://phpackages.com/packages/pixellair-laravel-discount-system)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
