Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

benholmen's avatar

Target class [ProductSeeder] does not exist.

Hello,

I'm using database seeders and just added a new one that will just not run. The new one is ProductSeeder.

Here's my DatabaseSeeder.php:

<?php

use Database\Seeders\OrderSeeder;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            UserSeeder::class,
            ProductSeeder::class,
            OrderSeeder::class,
            WishlistSeeder::class,
        ]);
    }
}

And here is my database/seeds/ProductSeeder.php:

<?php

namespace Database\Seeders;

use App\Models\User;
use App\Models\Product;
use App\Models\ProductImage;
use Illuminate\Database\Seeder;

class ProductSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
...
    }
}

I have done the most common recommendation (run composer dump-autoload) in every way I can think of and I still run into this issue when running php artisan migrate:fresh --seed or php artisan db:seed:

Target class [ProductSeeder] does not exist.

I can run it manually with a php artisan tinker session, no errors. I can run it by php artisan db:seed --class=ProductSeeder. But php artisan db:seed? No luck.

The other seeders work just fine. What else can I do to troubleshoot this?

0 likes
5 replies
Nakov's avatar
Nakov
Best Answer
Level 73

Are you running Laravel 8? Have you upgraded from Laravel 7? Take a look at the upgrade guide and follow all the steps including the update in the composer.json file and then run composer dump-autoload.

https://laravel.com/docs/master/upgrade#seeder-factory-namespaces

As I see you still have database/seeds as a folder which should be renamed as suggested to reflect the namespace that you use in the classes.

3 likes
rodrigo.pedra's avatar

If you just upgraded to Laravel 8 and didn't added the new database folder namespaces to your seeders, just remove the namespace from your ProductSeeder class, run composer dump-autoload again and test it out.

If that is the case, I would take @nakov 's advice and follow the upgrade guide very closely to ensure your app is up to date with the new Laravel version.

2 likes
benholmen's avatar

Thank you! I did upgrade this project from 7 -> 8 and I must have missed that step in the upgrade guide.

What solved it:

  1. Updating composer.json as specified
  2. Adding proper namespace to existing seeders generated with v7
  3. Renaming database/seeds to database/seeders
  4. Running composer dump-autoload

Thanks for the help!

2 likes
rodrigo.pedra's avatar

Great to learn you got it working! And glad my response was helpful.

If you think this could benefit others in the future, consider marking @nakov 's answer as a best reply, so it is easier for someone to see this thread is solved.

My answer was just complementary to his.

Have a nice day =)

2 likes
ZermattChris's avatar

As a total noob to Laravel, I'm constantly getting caught out by the "little things" -- had the same error as above, but as I'm on a fresh v10 install, spent 30 min baffled why I'm getting this error only on my production server...

As is usually the case, it was simply not paying attention.

php artisan db:seed --class=DaySeeder.php

The ".php" at the end of the command caused it to fail. Just a head's up for the next person learning who likes to mimic my style of mistakes :-)

Please or to participate in this conversation.