php – Laravel工厂无法找到名称为[factory]的工厂
发布时间:2020-12-14 19:37:55 所属栏目:大数据 来源:网络整理
导读:从下面的代码中,顶部的2个工厂工作,只有最后一个产生以下错误: InvalidArgumentException with message 'Unable to locate factory with name [default] [AppReply].' 输入此命令后,控制台中会显示错误: $threads-each(function ($thread) { factory('App
|
从下面的代码中,顶部的2个工厂工作,只有最后一个产生以下错误:
InvalidArgumentException with message 'Unable to locate factory with name [default] [AppReply].' 输入此命令后,控制台中会显示错误: $threads->each(function ($thread) { factory('AppReply',10)->create(['thread_id' => $thread->id]); });
我已经阅读了其他类似标题的帖子,但这似乎并非如此. Laravel 5.2: Unable to locate factory with name [default] $factory->define(AppUser::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(AppThread::class,function($faker){
return [
'user_id' => function () {
return factory('AppUser')->create()->id;
},'title' => $faker->sentence,'body' => $faker->paragraph
];
});
$factory->define(AppReply::class,function($faker){
return [
'thread_id' => function() {
return factory('AppThread')->create()->id;
},'user_id' => function () {
return factory('AppUser')->create()->id;
},'body' => $faker->paragraph
];
});
. 解决方法
尝试
$threads->each(function ($thread) { factory(AppReply::class,10)->create(['thread_id' => $thread->id]); });
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
