cms/app/Console/Commands/GenerateMediaCategory.php

59 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\MediaCategory;
use Illuminate\Console\Command;
class GenerateMediaCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'media-category:generate {amount?} {--user=}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate media categories';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$userId = $this->option('user') !== null ? $this->option('user') : 1;
$isAppMediaCategory = true;
$amount = $this->argument('amount');
if(!$amount) $amount = 1;
for($i = 0; $i < $amount; $i++) {
if($isAppMediaCategory) {
factory(MediaCategory::class)->state('app')->create([
'user_id' => $userId
]);
} else {
factory(MediaCategory::class)->create([
'user_id' => $userId
]);
}
}
}
}