PHP code example of boddasaad / laravel-discountable
1. Go to this page and download the library: Download boddasaad/laravel-discountable 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/ */
boddasaad / laravel-discountable example snippets
$student = Student::find(1);
// Check if the voucher is valid and can be applied (useful for UI validation before applying)
$student->checkVoucher('SUMMER2023', 100);
// Redeem the voucher, applying the discount
$student->redeemVoucher('SUMMER2023', 100);
return [
/*
* Database table name that will be used to store vouchers.
*/
'table' => 'vouchers',
/*
* Database table name that will be used to store voucher usages.
*/
'usage_table' => 'voucher_usages',
/*
* List of characters that will be used for voucher code generation.
*/
'characters' => '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',
/*
* Voucher code prefix.
*
* Example: foo
* Generated Code: foo-AGXF-1NH8
*/
'prefix' => null,
/*
* Voucher 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' => '-',
];
namespace App\Models;
use BoddaSaad\Voucher\Traits\CanRedeemVouchers;
class User extends Authenticatable
{
use CanRedeemVouchers;
# ...
}