PHP code example of tankonyako / promocodes

1. Go to this page and download the library: Download tankonyako/promocodes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tankonyako / promocodes example snippets


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

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

Promocodes::output($amount = 1);

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

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

Promocodes::check($code);

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

Promocodes::all();

Promocodes::disable($code);

Promocodes::clearRedundant();

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;

    // ...
}

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

$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

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

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

// bar

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

// bar
bash
$ php artisan vendor:publish
bash
$ php artisan migrate