问题描述:

执行php artisan db:seed指令报错:Unable to locate factory with name [default] [App\Models\Status].

解决方案:

database/factories中创建的工厂类中,引用的模型类路径不正确。
因为工厂类是指令生成的,默认模型为Model

use Faker\Generator as Faker;

$factory->define(Model::class, function (Faker $faker) {
    $date_time = $faker->date . ' ' . $faker->time;
    return [
        'content' => $faker->text,
        'created_at' => $date_time,
        'updated_at' => $date_time
    ];
});

所以需要将Model改为指定需要批量生成数据的模型,如App\Models\User
即改成:

use Faker\Generator as Faker;

$factory->define(App\Models\User::class, function (Faker $faker) {
    $date_time = $faker->date . ' ' . $faker->time;
    return [
        'content' => $faker->text,
        'created_at' => $date_time,
        'updated_at' => $date_time
    ];
});

转:laravel-china
StatusFactory.php 里面
AppModelsStatus::class 写全了吗