PHP code example of aberkanidev / laravel-coupons

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

    

aberkanidev / laravel-coupons example snippets


$item = Item::find(1);
$customer = Customer::find(1);

$coupon = $Item->createDisposableCoupon();

$customer->redeemCoupon($coupon);



return [

    /*
     * Database table name that will be used in migration
     */
    'table' => 'coupons',

    /*
     * Database table name for voucherable models
     */
    'voucherable_table' => 'voucherables',

    /*
     * List of characters that will be used for coupon code generation.
     */
    'characters' => '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',

    /*
     * Coupon code prefix.
     *
     * Example: foo
     * Generated Code: foo-AGXF-1NH8
     */
    'prefix' => null,

    /*
     * Coupon code suffix.
     *
     * Example: foo
     * Generated Code: AGXF-1NH8-foo
     */
    'suffix' => null,

    /*
     * Code mask.
     * All asterisks will be removed by random characters.
     */
    'mask' => '****-****',

    /*
     * Separator to be used between prefix, code and suffix.
     */
    'separator' => '-',
];

$item = Item::find(1);

// Create 10 coupons using the Facade
// Returns an array of Coupons
$coupons = Coupons::create($item, 5);

// Create 3 coupons using the Eloquent model
// Returns an array of Coupons
$coupons = $item->createCoupons(2);

// Create a single coupon
$coupons = $item->createCoupon();


$item = Item::find(1);

// Create a disposable coupon
$coupon = $item->createDisposableCoupon();

$item = Item::find(1);

$coupons = $item->createCoupons(4, [
    'amount' => '150',
    'recipient_name' => 'Mohamed Aberkani'
		'recipient_email' => '[email protected]'
]);

$coupons = $coupons[0];
$coupon->data->get('amount');
$coupon->data->get('recipient_name');
$coupon->data->get('recipient_email');

$item = Item::find(1);

$item->createCoupons(4, [], today()->addDays(3));

$customer = Customer::find(1);

// Redeem using the code
// Returns the Coupon model
$coupon = $customer->redeem('ABCD-EFGH');

$customer = Customer::find(1);

$item = Item::find(1);

// Create Coupon
$coupon = $item->createCoupon();

// Redeem the Coupon Model
$coupon = $customer->redeemCoupon($coupon);

$customer = Customer::find(1);
$coupon = $customer->redeemCoupon('ABCD-EFGH');

$item = $coupon->model
bash
php artisan vendor:publish --provider="aberkanidev\Coupons\CouponsServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="aberkanidev\Coupons\CouponsServiceProvider" --tag="config"