Created
August 23, 2016 23:46
-
-
Save vinicius73/4987284a35802b1109dc27115d41e1a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
use App\Domains\ActLogs\ActLog; | |
use App\Domains\Finance\Account; | |
class LogsTableSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
$count = $this->accounts(); | |
$this->command->comment($count.' protocols created'); | |
} | |
protected function accounts() | |
{ | |
ActLog::query()->where('item_type', Account::class)->delete(); | |
$count = 0; | |
$accounts = Account::query()->limit(mt_rand(5, 10))->get(); | |
foreach ($accounts as $account) { | |
$count += $this->addActLogs($account); | |
} | |
return $count; | |
} | |
/** | |
* @param \Orios\Domains\ActLogs\Contracts\LogableItem $model | |
* @return int | |
*/ | |
protected function addActLogs($model) | |
{ | |
$max = mt_rand(2, 6); | |
for ($i = $max; $i > 0; $i--) { | |
$model->logs()->save($this->makeActLog()); | |
} | |
return $max; | |
} | |
/** | |
* @return ActLog | |
*/ | |
protected function makeActLog() | |
{ | |
return new ActLog(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment