PHPackages                             boddasaad/laravel-discountable - 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. boddasaad/laravel-discountable

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

boddasaad/laravel-discountable
==============================

Allow your laravel models to redeem vouchers and apply discounts.

v1.0.1(10mo ago)22[3 PRs](https://github.com/BoddaSaad/laravel-discountable/pulls)MITPHPPHP ^8.2CI passing

Since Jun 19Pushed 1mo agoCompare

[ Source](https://github.com/BoddaSaad/laravel-discountable)[ Packagist](https://packagist.org/packages/boddasaad/laravel-discountable)[ Docs](https://github.com/boddasaad/laravel-discountable)[ GitHub Sponsors]()[ RSS](/packages/boddasaad-laravel-discountable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (6)Used By (0)

[![Laravel Discountable](https://camo.githubusercontent.com/d88f2e038e108df46a24ec36e5f280ae365b99ae1413e0ad1df55f7a6ed7d734/68747470733a2f2f626c6f676765722e676f6f676c6575736572636f6e74656e742e636f6d2f696d672f622f523239765a32786c2f415676587345686653514c797739434a6a38307043447a4e6b55796535574e35703546683858516e463442467a6a3657443275734d4c715f7346512d79774630447967352d7a6b5f61373063543345364e646c39764b3051326375613341654f344e506f6c364a2d7542445a2d4f46455a354f64727354493877776b79446f316d646444464a6d776c59647361434f633165327672394163494932624453475838426c4b7367756f4b42773144353365736e356c695470504e687974397253562d5035732f73313630302f62616e6e65722e706e67)](https://camo.githubusercontent.com/d88f2e038e108df46a24ec36e5f280ae365b99ae1413e0ad1df55f7a6ed7d734/68747470733a2f2f626c6f676765722e676f6f676c6575736572636f6e74656e742e636f6d2f696d672f622f523239765a32786c2f415676587345686653514c797739434a6a38307043447a4e6b55796535574e35703546683858516e463442467a6a3657443275734d4c715f7346512d79774630447967352d7a6b5f61373063543345364e646c39764b3051326375613341654f344e506f6c364a2d7542445a2d4f46455a354f64727354493877776b79446f316d646444464a6d776c59647361434f633165327672394163494932624453475838426c4b7367756f4b42773144353365736e356c695470504e687974397253562d5035732f73313630302f62616e6e65722e706e67)

Discountable
============

[](#discountable)

Make your models discountable with Laravel, allowing you to apply vouchers with lots of options and conditions. Here's a quick example of how to use the package:

```
$student = Student::find(1);
// Check if the voucher is valid and can be applied (useful for UI validation before applying)
$student->checkVoucher('SUMMER2023', 100);

// Redeem the voucher, applying the discount
$student->redeemVoucher('SUMMER2023', 100);
```

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require boddasaad/laravel-discountable

php artisan discountable:install
```

This is the contents of the published config file:

```
return [
    /*
     * Database table name that will be used to store vouchers.
     */
    'table' => 'vouchers',

    /*
     * Database table name that will be used to store voucher usages.
     */
    'usage_table' => 'voucher_usages',

    /*
     * List of characters that will be used for voucher code generation.
     */
    'characters' => '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',

    /*
     * Voucher code prefix.
     *
     * Example: foo
     * Generated Code: foo-AGXF-1NH8
     */
    'prefix' => null,

    /*
     * Voucher code suffix.
     *
     * Example: foo
     * Generated Code: AGXF-1NH8-foo
     */
    'suffix' => null,

    /*
     * Code mask.
     * All asterisks will be removed by random characters.
     */
    'mask' => '****-****',

    /*
     * Separator to be used between prefix, code and suffix.
     */
    'separator' => '-',
];
```

Usage
-----

[](#usage)

To use the package, you need to add the `CanRedeemVouchers` trait to your model:

```
namespace App\Models;

use BoddaSaad\Voucher\Traits\CanRedeemVouchers;

class User extends Authenticatable
{
    use CanRedeemVouchers;
    # ...
}
```

Creating Vouchers
-----------------

[](#creating-vouchers)

You can create vouchers using the `Voucher` Facade. Here's an example of how to create a voucher with various options:

```
use BoddaSaad\Voucher\Facades\Voucher;

$voucher = Voucher::maximumRedeems(1000)
        ->discount('percentage', 20)
        ->date('2025-01-01', '2025-12-31')
        ->minimumQualifyingAmount(50)
        ->maximumDiscountAmount(100)
        ->maxUsagesPerModel(1)
        ->data(['description' => 'Holiday Discount'])
        ->create();
```

### Voucher Facade Methods

[](#voucher-facade-methods)

MethodDescription`discount(type, value)`If `type` is `percentage`, `value` should be between 0 and 100. If `type` is `fixed`, `value` should be a positive number.`maximumRedeems(int $max)`This limits how many times the voucher can be redeemed in total.`date(start, end)`Both dates should be in `Y-m-d` format. The voucher will be valid between these dates.`minimumQualifyingAmount(n)`This is the minimum amount that must be spent to apply the voucher.`maximumDiscountAmount(n)`This limits the discount to a maximum value. For percentage discounts, this is the maximum amount that can be discounted.`maxUsagesPerModel(n)`This limits how many times a single model can use the voucher.`data(array $data)`This can be any additional information you want to store with the voucher, such as a description or terms and conditions.`prefix(string $prefix)`This allows you to specify a prefix for the voucher code dynamically.`suffix(string $suffix)`This allows you to specify a suffix for the voucher code dynamically.`separator(string $sep)`This allows you to specify a custom separator for the voucher code dynamically.`create()`This method will generate the voucher code and save it to the database. (MUST BE CALLED LAST)Applying Vouchers
-----------------

[](#applying-vouchers)

To apply a voucher, you can use the `checkVoucher` and `redeemVoucher` methods provided by the `CanRedeemVouchers` trait.

### Check Voucher Validity

[](#check-voucher-validity)

This is useful for UI validation before applying the voucher so the user can see if the voucher is valid or not.:

```
auth()->user()->checkVoucher('SUMMER2023', 100);
```

This will return an object with the following properties if the voucher is valid:

```
[
    'valid' => true,
    'final_amount' => 80, // The amount after applying the voucher
    'voucher_id' => 1 // The ID of the voucher
]
```

If the voucher is not valid, it will return an object with the following properties:

```
[
    'valid' => false,
    'message' => 'Voucher has expired' // The reason why the voucher is not valid
]
```

### Redeem Voucher

[](#redeem-voucher)

To redeem the voucher and apply the discount, you can use the `redeemVoucher` method:

```
auth()->user()->redeemVoucher('SUMMER2023', 100);
// Will return true if the voucher was successfully redeemed, or false if it was not.
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Abdur-Rahman Saad](https://github.com/BoddaSaad)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance74

Regular maintenance activity

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% 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

Every ~0 days

Total

2

Last Release

327d ago

### Community

Maintainers

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

---

Top Contributors

[![BoddaSaad](https://avatars.githubusercontent.com/u/44672778?v=4)](https://github.com/BoddaSaad "BoddaSaad (45 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravelvoucherdiscountscoupondiscountredeemAbdur-Rahman SaadBoddaSaaddiscountablelaravel-discountable

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/boddasaad-laravel-discountable/health.svg)

```
[![Health](https://phpackages.com/badges/boddasaad-laravel-discountable/health.svg)](https://phpackages.com/packages/boddasaad-laravel-discountable)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[frittenkeez/laravel-vouchers

Voucher system for Laravel 9+

5819.9k2](/packages/frittenkeez-laravel-vouchers)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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