Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Wallet/SetDiscountCommand.php
- This file was moved from src/app/Console/Commands/WalletSetDiscount.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands\Wallet; | ||||
use App\Console\Command; | use App\Console\Command; | ||||
class WalletSetDiscount extends Command | class SetDiscountCommand extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'wallet:set-discount {wallet} {discount}'; | protected $signature = 'wallet:set-discount {wallet} {discount}'; | ||||
Show All 9 Lines | class SetDiscountCommand extends Command | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallet = $this->getWallet($this->argument('wallet')); | $wallet = $this->getWallet($this->argument('wallet')); | ||||
if (!$wallet) { | if (!$wallet) { | ||||
$this->error("Wallet not found."); | |||||
return 1; | return 1; | ||||
} | } | ||||
// FIXME: Using '0' for delete might be not that obvious | // FIXME: Using '0' for delete might be not that obvious | ||||
if ($this->argument('discount') === '0') { | if ($this->argument('discount') === '0') { | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
} else { | } else { | ||||
$discount = $this->getObject(\App\Discount::class, $this->argument('discount')); | $discount = $this->getObject(\App\Discount::class, $this->argument('discount')); | ||||
if (!$discount) { | if (!$discount) { | ||||
$this->error("Discount not found."); | |||||
return 1; | return 1; | ||||
} | } | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
} | } | ||||
$wallet->save(); | $wallet->save(); | ||||
} | } | ||||
} | } |