Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Package/SkusCommand.php
- This file was added.
<?php | |||||
namespace App\Console\Commands\Package; | |||||
use App\Console\Command; | |||||
use App\Package; | |||||
class SkusCommand extends Command | |||||
{ | |||||
/** | |||||
* The name and signature of the console command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'package:skus {--package=}'; | |||||
/** | |||||
* The console command description. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = "List SKUs for package(s)."; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
if ($this->option('package')) { | |||||
$packages = Package::where('title', $this->option('package'))->get(); | |||||
} else { | |||||
$packages = Package::all(); | |||||
} | |||||
foreach ($packages as $package) { | |||||
$this->info("{$package->title}"); | |||||
foreach ($package->skus as $sku) { | |||||
$this->info(sprintf(" %s (%d)", $sku->title, $sku->pivot->qty)); | |||||
} | |||||
} | |||||
} | |||||
} |