PHP code example of trexology / promocodes

1. Go to this page and download the library: Download trexology/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/ */

    

trexology / promocodes example snippets


Trexology\Promocodes\PromocodesServiceProvider::class

'Promocodes' => Trexology\Promocodes\Facades\Promocodes::class

/**
 * @var bool
 */
public $timestamps = false;

/**
 * @var array
 */
protected $fillable = [
	'code',
	'reward',
	'quantity',
  'is_used',
];


Promocodes::generate(5); // $amount = 1

Promocodes::generateAndSave(5, 10.50); // $amount = 1, $reward = null

Example:

Promocodes::generateCodeName("OFF20%", 0.2); // $reward = null (percentage discount)
Promocodes::generateCodeName("5SGDOFF", 5); // $reward = null (dollar discount)

$valid = Promocodes::check('TEST-CODE'); // $promocode

$applied = Promocodes::apply('TEST-CODE', true); // $promocode, $hard_check = false

php artisan vendor:publish