Laravel, Call to undefined function Database\Seeders\factory()

后端 未结 5 1553
说谎
说谎 2021-01-05 07:46

I get the title error when I run command:

php artisan db:seed

My screenshot:

I have no idea where this problem comes from. I was sear

5条回答
  •  感动是毒
    2021-01-05 08:35

    In laravel 8 the default route namespace was removed.

    Try to change:

    ArticlesTableSeeder.php:

     factory(App\Models\Article::class, 30)->create();
    

    to:

    \App\Models\Article::factory()->count(30)->create(); 
    

    ArticleFactory.php:

    protected $model = App\Models\Article::class;
    

    to:

    protected $model = \App\Models\Article::class;
    

    and you will probably have to change:

     'title' => $faker->text(50),
                'body' => $faker->text(200)
    

    to:

     'title' => $this->faker->text(50),
            'body' => $this->faker->text(200)
    

提交回复
热议问题