Merge pull request #1158 from burakcakirel/sample-data-command
Sample data seeder
This commit is contained in:
commit
6ac725c582
47
app/Console/Commands/SampleData.php
Executable file
47
app/Console/Commands/SampleData.php
Executable 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
34
database/seeds/SampleData.php
Executable 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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user