Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created August 23, 2016 23:46
Show Gist options
  • Save vinicius73/4987284a35802b1109dc27115d41e1a2 to your computer and use it in GitHub Desktop.
Save vinicius73/4987284a35802b1109dc27115d41e1a2 to your computer and use it in GitHub Desktop.
<?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