From the below code, the 2 factory's on the top do work, just the last one gives the following error:
InvalidArgumentException with message 'Unable to locate factory with name [default] [App\Reply].'
The error shows in the console after putting in this command:
$threads->each(function ($thread) { factory('App\Reply', 10)->create(['thread_id' => $thread->id]); });
I have read the other post with a similar title, but that doesn't seem to be the case here.
Laravel 5.2: Unable to locate factory with name [default]
$factory->define(App\User::class, function (Faker $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});
$factory->define(App\Thread::class, function($faker){
return [
'user_id' => function () {
return factory('App\User')->create()->id;
},
'title' => $faker->sentence,
'body' => $faker->paragraph
];
});
$factory->define(App\Reply::class, function($faker){
return [
'thread_id' => function() {
return factory('App\Thread')->create()->id;
},
'user_id' => function () {
return factory('App\User')->create()->id;
},
'body' => $faker->paragraph
];
});
.