无法找到名称[默认] [主题]的工厂

I just want some dummy data that I can loop out from my database but when I try to using the seeder I get this error:

unable to locate factory with name [default] [Subject]

The code I run is:

php artisan db:seed --class=SubjectSeeder

ModelFactory.php:

$factory->define(App\Subject::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'code' => $faker->str_random(3),
        ];
});

SubjectSeeder.php:

public function run()
{
    $subject = factory(Subject::class)->make();

    Product::create([
        'name' => $subject->name,
        'code' => $subject->code
    ]);
}

subject.php:

class Subject extends Model
{
    protected $fillable = [
        'name', 'code',
    ];
};

SubjectSeeder.php:

$subject = factory(\APP\Subject::class)->make();

Answer by OddDream is correct.

Just to explain it more.

  1. Your model/object might not be linked properly.

    $subject = factory(\App\Subject::class)->make();

  2. Another reason is the cache. You might want to do something like.

    php artisan config:clear php artisan config:cache

Let me know if it helps you.

:)

If someone makes the same mistake as me, i tried just to define state factories, without default one:

$factory->define(\App\Model::class, function (Faker $faker) {