PHPackages                             abhibunt/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. abhibunt/promocodes

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

abhibunt/promocodes
===================

Promotional Codes Generator for Laravel 9

1.0(3y ago)06MITPHPPHP ^7.2||^8.0

Since Nov 30Pushed 3y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

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)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3ecb0567f4de294145b36d7a79bc357e26763df75ab9ab91fae0802919933640/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a676162696576692f6c61726176656c2d70726f6d6f636f6465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zgabievi/laravel-promocodes/?branch=master)[![Build Status](https://camo.githubusercontent.com/42ef9323a173d9a8c9c69fb7308e25f89b11fe5bf0372efc94821205720ced05/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a676162696576692f6c61726176656c2d70726f6d6f636f6465732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zgabievi/laravel-promocodes/build-status/master)

> Promocodes generator for [Laravel 5.\*](http://laravel.com/). Trying to make the best package in this category. You are welcome to join the party, give me some advices 🎉 and make pull requests.

[![laravel-promocodes](https://camo.githubusercontent.com/2f76a4c1dce9f76c6a90df2ae94b1a1334b38cbe22e73acd72ca7e12adce4990/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f50726f6d6f636f6465732e6a7065673f7468656d653d6c69676874267061636b6167654e616d653d7a676162696576692532466c61726176656c2d70726f6d6f636f646573267061747465726e3d746f706f677261706879267374796c653d7374796c655f31266465736372697074696f6e3d50726f6d6f74696f6e616c2b636f6465732b67656e657261746f722b666f722b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d746167)](https://github.com/zgabievi/laravel-promocodes)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Methods](#usage)
    - [User Trait](#promocodes-can-be-related-to-users)
    - [Additional Data](#how-to-use-additional-data)
- [Testing](#testing)
- [License](#license)

### What's new?

[](#whats-new)

- [Additional Data](#how-to-use-additional-data)

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

[](#installation)

Install this package via Composer:

```
$ composer require zgabievi/promocodes
```

> If you are using Laravel 5.5 or later, then installation is done. Otherwise follow the next steps.

#### Open `config/app.php` and follow steps below:

[](#open-configappphp-and-follow-steps-below)

Find the `providers` array and add our service provider.

```
'providers' => [
    // ...
    Gabievi\Promocodes\PromocodesServiceProvider::class
],
```

Find the `aliases` array and add our facade.

```
'aliases' => [
    // ...
    'Promocodes' => Gabievi\Promocodes\Facades\Promocodes::class
],
```

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

[](#configuration)

Publish config &amp; migration file using Artisan command:

```
$ php artisan vendor:publish
```

To create table for promocodes in database run:

```
$ php artisan migrate
```

> Configuration parameters are well documented. There is no need to describe each parameter here.

> Check `config/promocodes.php` and read comments there if you need.

Usage
-----

[](#usage)

Generate as many codes as you wish and output them without saving to database.

You will get array of codes in return:

```
Promocodes::output($amount = 1);
```

#### Parameters

[](#parameters)

nametypedescriptionrequired?$amountnumberNumber of items to be generatedNO---

Create as many codes as you wish. Set reward (amount).

Attach additional data as array. Specify for how many days should this codes stay alive.

By default generated code will be multipass (several users will be able to use this code once).

They will be saved in database and you will get collection of them in return:

```
Promocodes::create($amount = 1, $reward = null, array $data = [], $expires_in = null, $quantity = null, $is_disposable = false);
```

If you want to create code that will be used only once, here is method for you.

```
Promocodes::createDisposable($amount = 1, $reward = null, array $data = [], $expires_in = null, $quantity = null);
```

#### Parameters

[](#parameters-1)

nametypedescriptiondefaultrequired?$amountintegerNumber of promocodes to generate1NO$rewardfloatNumber of reward that user gets (ex: 30 - can be used as 30% sale on something)nullNO$dataarrayAny additional information to get from promocode\[\]NO$expires\_inintegerNumber of days to keed promocode validnullNO$quantityintegerHow many times can promocode be used?nullNO$is\_disposablebooleanIf promocode is one-time use onlyfalseNO---

Check if given code exists, is usable and not yet expired.

Returns `Promocode` object if valid, or `false` if not.

```
Promocodes::check($code);
```

#### Parameters

[](#parameters-2)

nametypedescriptionrequired?$codestringCode to be checked for validityYES---

If you want to check if user tries to use promocode for second time you can call `Promocodes::isSecondUsageAttempt` and pass `Promocode` object as an argument. As an answer you will get boolean value

---

Redeem or apply code. Redeem is alias for apply method.

User should be authenticated to redeem code or this method will throw an exception (`\Gabievi\Promocodes\Exceptions\UnauthenticatedException`).

Also if authenticated user will try to apply code twice, it will throw an exception (`\Gabievi\Promocodes\Exceptions\AlreadyUsedException`)

Returns `Promocode` object if applied, or `false` if not.

```
Promocodes::redeem($code);
Promocodes::apply($code);
```

#### Parameters

[](#parameters-3)

nametypedescriptionrequired?$codestringCode to be applied by authenticated userYES---

Get the collection of valid promotion codes.

```
Promocodes::all();
```

---

You can immediately expire code by calling *disable* function. Returning boolean status of update.

```
Promocodes::disable($code);
```

#### Parameters

[](#parameters-4)

nametypedescriptionrequired?$codestringCode to be set as invalidYES---

And if you want to delete expired, or non-usable codes you can erase them.

This method will remove redundant codes from database and their relations to users.

```
Promocodes::clearRedundant();
```

---

### Promocodes can be related to users

[](#promocodes-can-be-related-to-users)

If you want to use user relation open `app/User.php` and make it `Rewardable` as in example:

```
namespace App;

use Illuminate\Notifications\Notifiable;
use Gabievi\Promocodes\Traits\Rewardable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, Rewardable;

    // ...
}
```

---

Redeem or apply code are same. *redeemCode* is alias of *applyCode*

Pass promotion code you want to be applied by current user.

```
User::redeemCode($code, $callback = null);
User::applyCode($code, $callback = null);
```

Example (usage of callback):

```
$redeemMessage = $user->redeemCode('ABCD-DCBA', function ($promocode) use ($user) {
    return 'Congratulations, ' . $user->name . '! We have added ' . $promocode->reward . ' points on your account';
});

// Congratulations, Zura! We have added 10 points on your account
```

### How to use additional data?

[](#how-to-use-additional-data)

1. Process of creation:

```
Promocodes::create(1, 25, ['foo' => 'bar', 'baz' => 'qux']);
```

2. Getting data back:

```
Promocodes::redeem('ABC-DEF', function($promocode) {
    echo $promocode->data['foo'];
});

// bar
```

or

```
User::redeemCode('ABC-DEF', function($promocode) {
    echo $promocode->data['foo'];
});

// bar
```

Testing
-------

[](#testing)

Finally it's here. I've written some test to keep this package healthy and stable

[![laravel-promocodes tests](https://user-images.githubusercontent.com/1515299/29971701-4971da9e-8f3a-11e7-9f68-f7677400ef16.png)](https://user-images.githubusercontent.com/1515299/29971701-4971da9e-8f3a-11e7-9f68-f7677400ef16.png)

License
-------

[](#license)

laravel-promocodes is licensed under a [MIT License](https://github.com/zgabievi/laravel-promocodes/blob/master/LICENSE).

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1256d ago

### Community

Maintainers

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

---

Top Contributors

[![abhibunt](https://avatars.githubusercontent.com/u/33374391?v=4)](https://github.com/abhibunt "abhibunt (2 commits)")

---

Tags

phplaravelpromo codecoupon codediscount code

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[trexology/promocodes

Promotional Codes Generator for Laravel 5.1

121.2k](/packages/trexology-promocodes)[ronasit/laravel-helpers

Provided helpers function and some helper class.

1475.7k13](/packages/ronasit-laravel-helpers)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[salmanzafar/laravel-geocode

A Laravel Library to find Lat and Long of a given Specific Address

153.9k](/packages/salmanzafar-laravel-geocode)

PHPackages © 2026

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