PHPackages                             zgabievi/promocodes - 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. zgabievi/promocodes

Abandoned → [zgabievi/laravel-promocodes](/?search=zgabievi%2Flaravel-promocodes)ArchivedLibrary

zgabievi/promocodes
===================

:package\_description

9.1.0(3y ago)56791.3k↓95.6%138[3 issues](https://github.com/zgabievi/laravel-promocodes/issues)[8 PRs](https://github.com/zgabievi/laravel-promocodes/pulls)1MITPHPPHP ^8.1

Since Nov 24Pushed 2y ago8 watchersCompare

[ Source](https://github.com/zgabievi/laravel-promocodes)[ Packagist](https://packagist.org/packages/zgabievi/promocodes)[ Docs](https://github.com/zgabievi/laravel-promocodes)[ RSS](/packages/zgabievi-promocodes/feed)WikiDiscussions release/9.0 Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (46)Used By (1)

[![#StandWithUkraine](https://camo.githubusercontent.com/2bedf63f24cda7efab02da955dc11fb7ef8a060e2f26b73c33a7aac84529b8a3/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31)](https://supportukrainenow.org)[![laravel-promocodes](https://camo.githubusercontent.com/d1e577a80600e8dc6ae77bb10ba12c63a4fc75f7e14d819723d4bc1d4c04f4d3/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f6c61726176656c2d70726f6d6f636f6465732e6a7065673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7a676162696576692532466c61726176656c2d70726f6d6f636f646573267061747465726e3d746f706f677261706879267374796c653d7374796c655f32266465736372697074696f6e3d436f75706f6e732b616e642b70726f6d6f74696f6e616c2b636f6465732b67656e657261746f722e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://github.com/zgabievi/laravel-promocodes)

laravel-promocodes
==================

[](#laravel-promocodes)

[![Packagist](https://camo.githubusercontent.com/70558e6d07222ec037de90e060cee6fce4fe79bbdca788237eeb82eef2ffd224/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a676162696576692f70726f6d6f636f6465732e737667)](https://packagist.org/packages/zgabievi/promocodes)[![Packagist](https://camo.githubusercontent.com/02fae729287ed12f917969864b948db7a762aadfe43c681c73593c6290a6a809/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a676162696576692f70726f6d6f636f6465732e737667)](https://packagist.org/packages/zgabievi/promocodes)[![license](https://camo.githubusercontent.com/b5ad8e0d8eafc3201514aeead7d6ac1b91dddf68d611c46b95021dc5e8ebd743/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a676162696576692f70726f6d6f636f6465732e737667)](https://packagist.org/packages/zgabievi/promocodes)

Coupons and promotional codes generator for [Laravel](https://laravel.com). Current release is only for [Laravel 9.x](https://laravel.com/docs/9.x) and [PHP 8.1](https://www.php.net/releases/8.1/en.php). It's completely rewritten, and if you are using previous version, you should change your code accordingly. Code is simplified now and it should take you several minutes to completely rewrite usage.

> **Attention:**Current version is completely rewritten. If you are missing some functionality, that was possible to achieve in previous versions, fill free to open issue. Hope this new version will be easier to use, and it will provide better functionality for your needs.

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

[](#installation)

You can install the package via composer:

```
composer require zgabievi/laravel-promocodes
```

Configuration
-------------

[](#configuration)

```
php artisan vendor:publish --provider="Zorb\Promocodes\PromocodesServiceProvider"
```

Now you can change configurations as you need:

```
return [
    'models' => [
        'promocodes' => [
            'model' => \Zorb\Promocodes\Models\Promocode::class,
            'table_name' => 'promocodes',
            'foreign_id' => 'promocode_id',
        ],

        'users' => [
            'model' => \App\Models\User::class,
            'table_name' => 'users',
            'foreign_id' => 'user_id',
        ],

        'pivot' => [
            'model' => \Zorb\Promocodes\Models\PromocodeUser::class,
            'table_name' => 'promocode_user',
        ],
    ],
    'code_mask' => '****-****',
    'allowed_symbols' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789',
];
```

After you configure this file, run migrations:

```
php artisan migrate
```

Now you will need to use AppliesPromocode on your user model.

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Zorb\Promocodes\Traits\AppliesPromocode;

class User extends Authenticatable {
    use AppliesPromocode;

    //
}
```

Usage
-----

[](#usage)

It's very easy to use. Methods are combined, so that you can configure promocodes easily.

- [Reference](#reference)
- [Creating Promocodes](#creating-promocodes)
- [Generating Promocodes](#creating-promocodes)
- [Applying Promocode](#applying-promocode)
- [Expiring Promocode](#expiring-promocode)
- [Additional Methods](#additional-methods)

Reference
---------

[](#reference)

NameExplanationMaskAstrisks will be replaced with random symbolCharactersAllowed symbols to use in mask replacementMulti useDefine if single code can be used multiple times, by the same userUnlimitedGenerated code will have unlimited usagesBound to userDefine if promocode can be used only one user, if user is not assigned initially, first user will be bound to promocodeUserDefine user who will be initially bound to promocodeCountAmount of unique promocodes should be generatedUsagesDefine how many times can promocode be usedExpirationDateTime when promocode should be expired. Null means that promocode will never expireDetailsArray of details which will be retrieved upon applyCreating Promocodes
-------------------

[](#creating-promocodes)

### Using class

[](#using-class)

Combine methods as you need. You can skip any method that you don't need, most of them already have default values.

```
use Zorb\Promocodes\Facades\Promocodes;

Promocodes::mask('AA-***-BB') // default: config('promocodes.code_mask')
          ->characters('ABCDE12345') // default: config('promocodes.allowed_symbols')
          ->multiUse() // default: false
          ->unlimited() // default: false
          ->boundToUser() // default: false
          ->user(User::find(1)) // default: null
          ->count(5) // default: 1
          ->usages(5) // default: 1
          ->expiration(now()->addYear()) // default: null
          ->details([ 'discount' => 50 ]) // default: []
          ->create();
```

### Using helper

[](#using-helper)

There is a global helper function which will do the same as promocodes class. You can use named arguments magic from php 8.1.

```
createPromocodes(
    mask: 'AA-***-BB', // default: config('promocodes.code_mask')
    characters: 'ABCDE12345', // default: config('promocodes.allowed_symbols')
    multiUse: true, // default: false
    unlimited: true, // default: false
    boundToUser: true, // default: false
    user: User::find(1), // default: null
    count: 5, // default: 1
    usages: 5, // default: 1
    expiration: now()->addYear(), // default: null
    details: [ 'discount' => 50 ] // default: []
);
```

### Using command

[](#using-command)

There is also the command for creating promocodes. Parameters are optional here too.

```
php artisan promocodes:create\
  --mask="AA-***-BB"\
  --characters="ABCDE12345"\
  --multi-use\
  --unlimited\
  --bound-to-user\
  --user=1\
  --count=5\
  --usages=5\
  --expiration="2022-01-01 00:00:00"
```

### Generating Promocodes

[](#generating-promocodes)

If you want to output promocodes and not save them to database, you can call generate method instead of create.

```
use Zorb\Promocodes\Facades\Promocodes;

Promocodes::mask('AA-***-BB') // default: config('promocodes.code_mask')
          ->characters('ABCDE12345') // default: config('promocodes.allowed_symbols')
          ->multiUse() // default: false
          ->unlimited() // default: false
          ->boundToUser() // default: false
          ->user(User::find(1)) // default: null
          ->count(5) // default: 1
          ->usages(5) // default: 1
          ->expiration(now()->addYear()) // default: null
          ->details([ 'discount' => 50 ]) // default: []
          ->generate();
```

### Applying Promocode

[](#applying-promocode)

### Using class

[](#using-class-1)

Combine methods as you need. You can skip any method that you don't need.

```
use Zorb\Promocodes\Facades\Promocodes;

Promocodes::code('ABC-DEF')
          ->user(User::find(1)) // default: null
          ->apply();
```

### Using helper

[](#using-helper-1)

There is a global helper function which will do the same as promocodes class.

```
applyPomocode(
    'ABC-DEF',
    User::find(1) // default: null
);
```

### Using command

[](#using-command-1)

There is also the command for applying promocode.

```
php artisan promocodes:apply ABC-DEF --user=1
```

#### Exceptions

[](#exceptions)

While trying to apply promocode, you should be aware of exceptions. Most part of the code throws exceptions, when there is a problem:

```
// Zorb\Promocodes\Exceptions\*

PromocodeAlreadyUsedByUserException - "The given code `ABC-DEF` is already used by user with id 1."
PromocodeBoundToOtherUserException - "The given code `ABC-DEF` is bound to other user, not user with id 1."
PromocodeDoesNotExistException - "The given code `ABC-DEF` doesn't exist." | "The code was not event provided."
PromocodeExpiredException - "The given code `ABC-DEF` already expired."
PromocodeNoUsagesLeftException - "The given code `ABC-DEF` has no usages left."
UserHasNoAppliesPromocodeTrait - "The given user model doesn't have AppliesPromocode trait."
UserRequiredToAcceptPromocode - "The given code `ABC-DEF` requires to be used by user, not by guest."
```

#### Events

[](#events)

There are two events which are fired upon applying.

```
// Zorb\Promocodes\Events\*

GuestAppliedPromocode // Fired when guest applies promocode
    // It has public variable: promocode

UserAppliedPromocode // Fired when user applies promocode
    // It has public variable: promocode
    // It has public variable: user
```

### Expiring Promocode

[](#expiring-promocode)

### Using helper

[](#using-helper-2)

There is a global helper function which will expire promocode.

```
expirePromocode('ABC-DEF');
```

### Using command

[](#using-command-2)

There is also the command for expiring promocode.

```
php artisan promocodes:expire ABC-DEF
```

Trait Methods
-------------

[](#trait-methods)

If you added AppliesPromocode trait to your user model, you will have some additional methods on user.

```
$user = User::find(1);

$user->appliedPromocodes // Returns promocodes applied by user
$user->boundPromocodes // Returns promocodes bound to user
$user->applyPromocode('ABC-DEF') // Applies promocode to user
```

Additional Methods
------------------

[](#additional-methods)

```
Promocodes::all(); // To retrieve all (available/not available) promocodes
Promocodes::available(); // To retrieve valid (available) promocodes
Promocodes::notAvailable(); // To retrieve invalid (not available) promocodes
```

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/zgabievi/laravel-promocodes/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Zura Gabievi](https://github.com/zgabievi)
- [All Contributors](https://github.com/zgabievi/laravel-promocodes/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/zgabievi/laravel-promocodes/blob/master/LICENSE.md)for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% 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 ~65 days

Recently: every ~165 days

Total

38

Last Release

1399d ago

Major Versions

0.5.4 → 1.0.02017-08-29

1.2.0 → 2.0.02018-07-07

2.3.3 → 8.0.02020-09-13

2.1.2 → 8.1.02020-09-16

8.1.2 → 9.0.02022-03-13

PHP version history (6 changes)0.1.0PHP &gt;=5.4.0

1.1.0PHP ^7.0

1.2.0PHP ^7.1

2.3.0PHP ^7.2

8.1.2PHP ^7.2||^8.0

9.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/97b2001280ff47bbc67e542074e290919291715cd6c9f694e6787b50d67c60ad?d=identicon)[zgabievi](/maintainers/zgabievi)

---

Top Contributors

[![zgabievi](https://avatars.githubusercontent.com/u/1515299?v=4)](https://github.com/zgabievi "zgabievi (11 commits)")

---

Tags

couponspromo-codeslaravelpromocodes

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/zgabievi-promocodes/health.svg)

```
[![Health](https://phpackages.com/badges/zgabievi-promocodes/health.svg)](https://phpackages.com/packages/zgabievi-promocodes)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M531](/packages/laravel-passport)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[aedart/athenaeum

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

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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