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

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

fsuuaas/promocodes
==================

Promotional Codes Generator for Laravel 5

2.4(6y ago)045MITPHPPHP &gt;=7.2

Since Jul 13Pushed 3y agoCompare

[ Source](https://github.com/fsuuaas/laravel-promocodes)[ Packagist](https://packagist.org/packages/fsuuaas/promocodes)[ Docs](https://github.com/fsuuaas/promocodes)[ RSS](/packages/fsuuaas-promocodes/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

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

[](#laravel-promocodes)

> 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.

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 fsuuaas/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' => [
    // ...
    Fsuuaas\Promocodes\PromocodesServiceProvider::class
],
```

Find the `aliases` array and add our facade.

```
'aliases' => [
    // ...
    'Promocodes' => Fsuuaas\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.

This code may throw `\Fsuuaas\Promocodes\Exceptions\InvalidPromocodeException` if there is not such promocode in database, with give code.

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 (`\Fsuuaas\Promocodes\Exceptions\UnauthenticatedException`).

Also if authenticated user will try to apply code twice, it will throw an exception (`\Fsuuaas\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 Fsuuaas\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
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% 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 ~96 days

Total

3

Last Release

2302d ago

PHP version history (2 changes)v2.3.1PHP ^7.1

2.3.2PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![colorclipping](https://avatars.githubusercontent.com/u/52049362?v=4)](https://github.com/colorclipping "colorclipping (4 commits)")[![fsuuaas](https://avatars.githubusercontent.com/u/9248893?v=4)](https://github.com/fsuuaas "fsuuaas (3 commits)")

---

Tags

phplaravelpromo codecoupon codediscount code

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/fsuuaas-promocodes/health.svg)](https://phpackages.com/packages/fsuuaas-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)[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)
