### Install and migrate coupons-for-laravel Source: https://github.com/roundly-consulting/coupons-for-laravel/blob/main/README.md Install the package via Composer, publish the migrations, and run the migrations. Requires PHP 8.4 with ext-bcmath, Laravel 12 or 13, and MySQL/MariaDB, PostgreSQL, or SQLite. If models have UUID/ULID keys, set COUPONS_KEY_TYPE before migrating. ```bash composer require roundly-consulting/coupons-for-laravel php artisan vendor:publish --tag="coupons-migrations" php artisan migrate ``` -------------------------------- ### Generate and activate a coupon Source: https://github.com/roundly-consulting/coupons-for-laravel/blob/main/README.md Create a coupon using the Coupons facade. New coupons start inactive, so call activate() and save(). The example creates a 20% off coupon with code 'SUMMER' and maxUsage 100. ```php 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(); ``` -------------------------------- ### Check, preview, and redeem a coupon at checkout Source: https://github.com/roundly-consulting/coupons-for-laravel/blob/main/README.md At checkout, check the coupon against the cart and user, preview the discount without redeeming, and redeem atomically. redeem() throws a CouponException if refused. The example shows a €50.00 cart and a 10.00 EUR discount, resulting in a 40.00 EUR total. ```php 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 ```