Laravel数据填充错误

使用模型进行数据填充,官方文档少说了一个步骤,会导致错误

 [InvalidArgumentException] 
 Unable to locate factory with name [default] [App\Comment].

需要先在database/factories/ModelFactory.php中定义:

$factory->define(App\Comment::class, function (Faker\Generator $faker) {
 return [
 'user_id' => $faker->numberBetween(1,50),
 'text' => $faker->text(),
 ];
});