1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MichaelRubel\Couponables\Commands; |
6
|
|
|
|
7
|
|
|
use Illuminate\Console\Command; |
8
|
|
|
use MichaelRubel\Couponables\Models\Contracts\CouponContract; |
9
|
|
|
|
10
|
|
|
class MakeCouponCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'make:coupon |
16
|
|
|
{code : Coupon name to verify and redeem} |
17
|
|
|
{--value= : The `value` to perform calculations based on the coupon provided} |
18
|
|
|
{--type= : The `type` to point out calculation strategy} |
19
|
|
|
{--limit= : Limit how many times the coupon can be applied by the model} |
20
|
|
|
{--quantity= : Limit how many coupons are available overall (this value will decrement)} |
21
|
|
|
{--expires_at= : Set expiration time for the coupon} |
22
|
|
|
{--redeemer_type= : Polymorphic model type. Can as well be morph-mapped value, i.e. `users`} |
23
|
|
|
{--redeemer_id= : Redeemer model ID} |
24
|
|
|
{--data= : JSON column to store any metadata you want for this particular coupon}'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Add the coupon to database'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
1 |
|
public function handle(): void |
35
|
|
|
{ |
36
|
1 |
|
$coupon = app(CouponContract::class); |
37
|
|
|
|
38
|
1 |
|
$coupon->create([ |
|
|
|
|
39
|
1 |
|
$coupon->getCodeColumn() => $this->argument('code'), |
40
|
1 |
|
$coupon->getValueColumn() => $this->option('value'), |
41
|
1 |
|
$coupon->getTypeColumn() => $this->option('type'), |
42
|
1 |
|
$coupon->getLimitColumn() => $this->option('limit'), |
43
|
1 |
|
$coupon->getQuantityColumn() => $this->option('quantity'), |
44
|
1 |
|
$coupon->getExpiresAtColumn() => $this->option('expires_at'), |
45
|
1 |
|
$coupon->getRedeemerTypeColumn() => $this->option('redeemer_type'), |
46
|
1 |
|
$coupon->getRedeemerIdColumn() => $this->option('redeemer_id'), |
47
|
1 |
|
$coupon->getDataColumn() => $this->option('data'), |
48
|
1 |
|
]); |
49
|
|
|
|
50
|
1 |
|
$this->info('The coupon was added to the database successfully!'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|