1. Go to this page and download the library: Download tasmidur/coupon 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/ */
tasmidur / coupon example snippets
return [
/*
* Table that will be used for migration
*/
'table' => 'coupons',
/*
* Model to use
*/
'model' => \Tasmidur\Coupon\Models\Coupon::class,
/*
* Pivot table name for coupons and other table relation
*/
'relation_table' => 'coupon_applied',
/*
* Pivot table model name for coupons and other table relation
*/
'relation_model_class' => \App\Models\Course::class,
/*
* List of characters that will be used for Coupons code generation.
*/
'coupon_mix_characters' => '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
/*
* Coupons code prefix.
*
* Example: course2022
* Generated Code: course2022-37JH-1PUY
*/
'prefix' => null,
/*
* Coupons code suffix.
*
* Example: course2022
* Generated Code: 37JH-1PUY-course2022
*/
'suffix' => null,
/*
* Separator to be used between prefix, code and suffix.
*/
'separator' => '-',
'coupon_format'=>'*****-*****'
];
//Use for Create
$coupon = Coupons::createCoupon(string $couponType, float $price, Carbon|null $expiredAt = null, int $totalAmount = 1);
//Use for get Coupon List
$coupon = Coupons::getCouponList(string $sortBy = "id", string $orderBy = "ASC");
$coupon = Coupons::getCouponListWithPagination(int $length = 10, string $sortBy = "id", string $orderBy = "ASC");
$coupon = Coupons::deleteCoupon(int $id);
$coupon = Coupons::getCoupon(int $id);
//Use for update Coupon List
$coupon = Coupons::updateCoupon(array $payload, int $id);
//Use for validity check of Coupon
$coupon = Coupons::check(string $code);
//return list of applied coupon where it applied
$coupon = Coupons::whereApplyCoupon(string $code);
$course = Course::findOrFail($courseId);
/** One Coupon Is for One Course */
$course->applyUniqueCoupon($couponCode);
/** all applied coupons that is associated with course */
$coupons = Course::eloquentQuery($sortBy, $orderBy, $searchValue)->with(['category', 'coupons'])->get();