PHP code example of roundly-consulting / coupons-for-laravel
1. Go to this page and download the library: Download roundly-consulting/coupons-for-laravel 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/ */
roundly-consulting / coupons-for-laravel example snippets
use RoundlyConsulting\Coupons\Enums\DiscountType;
use RoundlyConsulting\Coupons\Facades\Coupons;
$coupon = Coupons::generate(DiscountType::Percentage, value: 2000, code: 'SUMMER', maxUsage: 100); // 20 % off
$coupon->activate()->save();
use RoundlyConsulting\Money\Money;
$cart = Money::ofMinor(5000, 'EUR'); // €50.00
Coupons::code('SUMMER')->check($cart, $user); // null, or why not: Expired, AtMaxUsage, …
Coupons::code('SUMMER')->preview($cart); // 10.00 EUR, without redeeming
$result = Coupons::code('SUMMER')->redeem($cart, $user); // atomic; throws a CouponException if refused
$result->discount; // 10.00 EUR
$result->total; // 40.00 EUR
bash
composer vendor:publish --tag="coupons-migrations"
php artisan migrate