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

ActiveLibrary

beratkara/promocodes
====================

Promotional Codes Generator for Laravel 5

8.1.3(4y ago)053MITPHPPHP ^7.2||^8.0

Since Nov 24Pushed 4y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (43)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

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 57.4% 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 ~56 days

Recently: every ~66 days

Total

37

Last Release

1797d 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

PHP version history (5 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

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e90c83dcf8b2e3e2df2b8e63195ae55a02f46b238ef2ef0754f40e7fc5edb58?d=identicon)[beratkara](/maintainers/beratkara)

---

Top Contributors

[![zgabievi](https://avatars.githubusercontent.com/u/1515299?v=4)](https://github.com/zgabievi "zgabievi (35 commits)")[![gabiezur](https://avatars.githubusercontent.com/u/131362365?v=4)](https://github.com/gabiezur "gabiezur (8 commits)")[![OleksiiBrylin](https://avatars.githubusercontent.com/u/13660488?v=4)](https://github.com/OleksiiBrylin "OleksiiBrylin (7 commits)")[![abhij89](https://avatars.githubusercontent.com/u/15982920?v=4)](https://github.com/abhij89 "abhij89 (3 commits)")[![TheGeekyM](https://avatars.githubusercontent.com/u/8965415?v=4)](https://github.com/TheGeekyM "TheGeekyM (2 commits)")[![elnurxf](https://avatars.githubusercontent.com/u/2572412?v=4)](https://github.com/elnurxf "elnurxf (2 commits)")[![beratkara](https://avatars.githubusercontent.com/u/5419560?v=4)](https://github.com/beratkara "beratkara (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![ngunyimacharia](https://avatars.githubusercontent.com/u/12905222?v=4)](https://github.com/ngunyimacharia "ngunyimacharia (1 commits)")[![peterjaap](https://avatars.githubusercontent.com/u/431360?v=4)](https://github.com/peterjaap "peterjaap (1 commits)")

---

Tags

phplaravelpromo codecoupon codediscount code

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laracraft-tech/laravel-xhprof

Easy XHProf setup to profile your laravel application!

235321.4k](/packages/laracraft-tech-laravel-xhprof)[trexology/promocodes

Promotional Codes Generator for Laravel 5.1

121.2k](/packages/trexology-promocodes)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[umbrellio/laravel-ltree

Extension LTree (Postgres) for Laravel

34111.6k](/packages/umbrellio-laravel-ltree)[bavix/laravel-xhprof

Quick profiling of your code for Laravel

22156.6k](/packages/bavix-laravel-xhprof)

PHPackages © 2026

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