Merge pull request #1158 from burakcakirel/sample-data-command

Sample data seeder
This commit is contained in:
Denis Duliçi 2020-01-22 16:58:59 +03:00 committed by GitHub
commit 6ac725c582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands;
use Database\Seeds\SampleData as SampleDataSeeder;
use Illuminate\Console\Command;
class SampleData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sample-data:seed {--count=100 : total records for each item}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seed for sample data';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = $this->laravel->make(SampleDataSeeder::class);
$seeder = $class->setContainer($this->laravel)->setCommand($this);
$seeder->__invoke();
}
}

34
database/seeds/SampleData.php Executable file
View File

@ -0,0 +1,34 @@
<?php
namespace Database\Seeds;
use App\Abstracts\Model;
use App\Models\Banking\Account;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Purchase\Bill;
use App\Models\Sale\Invoice;
use Illuminate\Database\Seeder;
class SampleData extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::reguard();
$count = $this->command->option('count');
factory(Contact::class, (int)$count)->create();
factory(Item::class, (int)$count)->create();
factory(Account::class, (int)$count)->create();
factory(Bill::class, (int)$count)->create();
factory(Invoice::class, (int)$count)->create();
Model::unguard();
}
}