I think I have it working with the following:
public function run()
{
DB::table('brands')->delete();
DB::table('brandAccounts')->delete();
DB::table('brandAccountLogs')->delete();
$faker = Faker\Factory::create();
// Create Brands to work with
for ($records = 0; $records <= 50; $records++){
$brand = new Brand([
'name' => $faker->unique()->company,
'url' => $faker->unique()->domainName
]);
$brand->save();
//Create Brand Accounts to work with
for($accounts = 0; $accounts <= 10; $accounts++){
$brandAccount = new BrandAccount([
'network' => $faker->randomElement(array ('facebook','twitter','instagram')),
'network_id' => $faker->randomNumber(8)
]);
$brand->brandAccounts()->save($brandAccount);
// Create Brand Account Log entries
for($accounts = 0; $accounts <= 365; $accounts++){
if($accounts == 0){
$logTotal = $faker->randomNumber(5);
$date = Carbon::now();
$brandAccountLog = new BrandAccountLog([
'log' => $logTotal,
'created_at' => $date
]);
} else {
$logTotal += $faker->biasedNumberBetween(100,1000);
$date->addDay();
$brandAccountLog = new BrandAccountLog([
'log' => $logTotal,
'created_at' => $date
]);
}
$brandAccount->brandAccountLogs()->save($brandAccountLog);
}
}
}
}
Is there a more efficient way to do this?