Skip to content

Commit

Permalink
Added installation, usage notes to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alexblunck committed Nov 16, 2017
1 parent eb39e55 commit 8af0e09
Showing 1 changed file with 84 additions and 1 deletion.
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,88 @@
# coupons
Coupon generator for Laravel 5

[![Latest Version on Packagist](https://img.shields.io/packagist/v/blunck/coupons.svg?style=flat-square)](https://packagist.org/packages/blunck/coupons)

Coupon generator for Laravel 5.

## Installation

You can install the package via composer:

```bash
composer require blunck/coupons
```

The package includes a migration to create a `coupons` & `coupon_user` table:

```bash
php artisan migrate
```

Add `Redeemable` trait to `User` model:
```php
use Blunck\Coupons\Traits\Redeemable;

class User {
use Redeemable;

// ...
}
```

## Usage

#### Retrieve / Check if a coupon code is valid
```php
try {
$coupon = Coupons::check('AAAA-BBBB-CCCC');
} catch (CouponException $e) {
//
}
```

You can optionally pass a user instance as the 2nd argument to `Coupons::check` to check if user has already redeemed a non disposable coupon.

#### Redeem coupon
```php
$user->redeemCoupon($coupon);
```

Redeeming a coupon adds a record to the `coupon_user` pivot table.

#### Create Coupon
```php
/**
* Disposable coupons can only be used onece.
*
* @var boolean
*/
$is_disposable = true;

/**
* Coupon discount.
*
* @var float
*/
$discount = 10.50;

/**
* Days from now when coupon expires. If null
* coupon never expires.
*
* @var integer|null
*/
$expires_in = 30;

/**
* Additional data.
*
* @var array
*/
$data = ['note' => 'lorem ipsum'];

$coupon = Coupons::create($is_disposable, $discount, $expires_in, $data);
$code = $coupon->code;
```

## Acknowledgments
Architecture inspired by [laravel-promocodes](https://github.com/zgabievi/laravel-promocodes)

0 comments on commit 8af0e09

Please sign in to comment.