gpt4 book ai didi

php - Laravel 工厂无法找到名称为 [默认] 的工厂

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:04 24 4
gpt4 key购买 nike

从下面的代码来看,上面的 2 个工厂在工作,只有最后一个给出了以下错误:

InvalidArgumentException with message 'Unable to locate factory with    name [default] [App\Reply].'

输入此命令后控制台显示错误:

$threads->each(function ($thread) { factory('App\Reply', 10)->create(['thread_id' => $thread->id]); });

我已经阅读了另一篇标题相似的帖子,但这里似乎并非如此。

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
];
});

.

最佳答案

尝试

$threads->each(function ($thread) { factory(App\Reply::class, 10)->create(['thread_id' => $thread->id]); });

关于php - Laravel 工厂无法找到名称为 [默认] 的工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46076040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com