close

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

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel, Call to undefined function Database\Seeders\factory() in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel, Call to undefined function Database\Seeders\factory() Error Occurs?

Today I get the following error Laravel, Call to undefined function Database\Seeders\factory() in php.

How To Solve Laravel, Call to undefined function Database\Seeders\factory() Error ?

  1. How To Solve Laravel, Call to undefined function Database\Seeders\factory() Error ?

    To Solve Laravel, Call to undefined function Database\Seeders\factory() Error change
    factory(App\Models\Article::class, 30)->create(); ‍
    to
    \App\Models\Article::factory(30)->create();

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

    To Solve Laravel, Call to undefined function Database\Seeders\factory() Error change
    factory(App\Models\Article::class, 30)->create(); ‍
    to
    \App\Models\Article::factory(30)->create();

Solution 1

change

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

to

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

Solution 2


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)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment