Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletDiscount.php
Show All 33 Lines | class WalletDiscount extends Command | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallet = \App\Wallet::where('id', $this->argument('wallet'))->first(); | $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first(); | ||||
if (!$wallet) { | if (!$wallet || !$wallet->owner()->withTrashed()->withEnvTenant()->first()) { | ||||
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 = \App\Discount::find($this->argument('discount')); | $discount = \App\Discount::withEnvTenant()->find($this->argument('discount')); | ||||
if (!$discount) { | if (!$discount) { | ||||
return 1; | return 1; | ||||
} | } | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
} | } | ||||
$wallet->save(); | $wallet->save(); | ||||
} | } | ||||
} | } |