Yes there is a problem a contact factory creates a company but the company factory creates again a contact ...you are in a loop. I am not sure if this is the best way but this will not loop.
Change the company factory to this
$factory->define(Company::class, function (Faker $faker) {
return [
'name' => $faker->company,
'contact_id' => function() {
return factory(Contact::class)->create()->id;
},
'location_id' => factory(Location::class),
'company_type_id' => rand(1, 3),
];
});
Create a company but you don't have a contact yet, so set this to 0
$company = factory(Company::class)->create(['contact_id' => 0]);
Update contact factory
$factory->define(Contact::class, function (Faker $faker) {
return [
'company_id' => function() {
return factory(Company::class)->create()->id;
} ,
'user_category_id' => rand(1, 3),
'entry_date' => now(),
'key' => Str::random(16),
'email' => $faker->safeEmail
];
});
Create the contact
$contact = factory(Contact::class)->create(['company_id' => $company->id]);
Now we have also a contact so we can update company with this contact id.
$company->contact_id = $contact->id;
$company->save();
Change the user factory
$factory->define(User::class, function (Faker $faker) {
return [
'contact_id' => function() {
return factory(Contact::class)->create()->id;
},
'firstname' => $faker->firstName,
'lastname' => $faker->lastName,
'email' => $faker->unique()->safeEmail,
'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password,
'key' => Str::random(16),
'remember_token' => Str::random(10),
];
});
Last step, create the user
$user= factory(User::class)->create(['contact_id' => $contact->id]);