Home > Software engineering >  Upgrading Laravel 7 to 8, seeder issue
Upgrading Laravel 7 to 8, seeder issue

Time:07-23

I am seeing a lot of issues with the upgrade path from Laravel 7 to 8, but I encounter a different problem for which I cannot find an answer.

It is this one

Seeding: Database\Seeders\UsersTableSeeder

   Error 

  Call to undefined method Database\Factories\UserFactory::new()

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:737
    733▕     public static function factoryForModel(string $modelName)
    734▕     {
    735▕         $factory = static::resolveFactoryName($modelName);
    736▕ 
  ➜ 737▕         return $factory::new();
    738▕     }
    739▕ 
    740▕     /**
    741▕      * Specify the callback that should be invoked to guess factory names based on dynamic relationship names.

       1 vendor frames 
  2   database/seeders/UsersTableSeeder.php:17
      App\User::factory()

       7 vendor frames 
  10  database/seeders/DatabaseSeeder.php:15
      Illuminate\Database\Seeder::call()

CodePudding user response:

You have probably read in the Upgrade Guide from 7 to 8 that Factories and Seeders are changed in Laravel 8.

If you don't have many Factories and Seeders you can write them from scratch.

CodePudding user response:

I extended the wrong Factory class.

The one I was using was Faker\Factory but instead I must use Illuminate\Database\Eloquent\Factories\Factory.

It was probably because I used the 'import class' function of PHPStorm too quickly.

  • Related