class ExportFromDbCategories extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db_export:categories';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Db to seed file';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$objDbCategories = $this->getObjCategoriesDB();
$objDbProducts = $this->getObjProductsDB();
$file = "";
foreach ($objDbCategories as $key=>$category) {
foreach ($objDbProducts as $product) {
if ($category->id === $product->category_id) {
$file .= " [
'title' => '" . $category->title . "',
'type_show' => 'list',
'description_enabled' => " . ($product->description_enabled ? 'true' : 'false') . ",
'cashback_enabled' => false,
'cashback_percent' => 0,
'cashback_command' => null,
'enabled' => " . ($category->enabled ? 'true' : 'false') . "
],\n";
}
}
}
Storage::append('CategoriesTableSeeder.log', $file);
}
private function getObjCategoriesDB()
{
return DB::table('categories')->get();
}
private function getObjProductsDB()
{
return DB::table('products')->get();
}
}