我有一个叫TagQuestionFactory
的Laravel工厂,它是这样的:
public function definition()
{
return [
'tag_id' => $this->faker->numberBetween(1,50),
'que_id' => $this->faker->numberBetween(1,50),
];
}
在DatabaseSeeder,中,我添加了以下内容:
public function run()
{
TagQuestionFactory::factory(50)->create();
}
然后运行php artisan db:seed
,但返回以下错误:
BadMethodCallException
Database\Factories\TagQuestionFactory::factory方法不存在.
那么这里出了什么问题?我怎样才能解决这个问题?
发布于 2022-11-06 18:07:00
你应该像这样从模型中调用工厂
public function run()
{
TagQuestion::factory(50)->create();
}
或者你可以直接这样称呼它
public function run()
{
TagQuestionFactory::times(50)->create();
}
https://stackoverflow.com/questions/74335127
复制相似问题