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

mauroMaccio's avatar

[SOLVED] "ReflectionException: Class not exist" error with php artisan db:seed --class="FooSeeder"

SOLUTION: Removing namespacing from all seeds and editing DatabaseSeeder.php do the trick

Good morning,

It's my first post so probably i'll make some mistake, please be gentle :)

I made some Seeder in my Laravel 5.3 Project. If i execute

php artisan db:seed

everything go fine and all tables are seeded. But if i try to execute a single seed the error appears

php artisan db:seed --class=ProductQuantityTypeSeeder

[ReflectionException]                           
Class ProductQuantityTypeSeeder does not exist

I executed several times "php artisan clear-compiled", "composer dump-autoload", "php artisan optimize" with no success.

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "doctrine/dbal": "^2.5",
        "laravel/framework": "5.3.*",
        "laravelcollective/html": "^5.3.0",
        "yajra/laravel-datatables-oracle": "~6.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*",
        "barryvdh/laravel-ide-helper": "^2.2"
    },
    "autoload": {
        "classmap": [
            "database/migrations",
            "database/seeds"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": [
            "app/Libraries/Helpers.php"
        ]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan clear-compiled",
            "php artisan ide-helper:generate",
            "php artisan ide-helper:meta",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    }
}

DatabaseSeeder.php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(\App\Database\Seeds\ProductTypeSeeder::class);
        $this->call(\App\Database\Seeds\ProductQuantityTypeSeeder::class);
        $this->call(\App\Database\Seeds\ProductFrequencySeeder::class);
        $this->call(\App\Database\Seeds\UserLevelSeeder::class);
    }
}

ProductQuantityTypeSeeder.php

namespace App\Database\Seeds;

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ProductQuantityTypeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('es_acc_product_quantity_types')->delete();

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '1',
            'description' => 'AAA',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '2',
            'description' => 'BBB',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '3',
            'description' => 'CCC',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '4',
            'description' => 'DDD',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '5',
            'description' => 'EEE',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);

        DB::table('es_acc_product_quantity_types')->insert([
            'code' => '6',
            'description' => 'FFF',
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now()
        ]);
    }
}

Thank you for help

0 likes
4 replies
Fringe's avatar

Try adding app/Database/Seeds to your autoload:

"classmap": [
        "database/migrations",
        "database/seeds",
        "app/Database/Seeds"
     ],
mauroMaccio's avatar

Thank you for reply! @Fringe

I tried "app/Database/Seeds" and "Database/Seeds" and "App/Database/Seeds" (uppercase) too but everyone gives me this

composer dump-autoload

[RuntimeException]                                                                                  
Could not scan for classes inside "app/Database/Seeds" which does not appear to be a file nor a folder

(And obviously the seed give me the same error)

Am I missing some namespace maybe?

tykus's avatar
tykus
Best Answer
Level 104

First, classmap expects a path to scan for PHP files, not an actual namespace.

Next, do you really need to namespace your seeders? By default, there is none.

1 like
mauroMaccio's avatar

@tykus your question was the right input!

I removed "namespace App\Database\Seeds;" from all Seeds, edited DatabaseSeeder.php like this:

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(ProductTypeSeeder::class);
        $this->call(ProductQuantityTypeSeeder::class);
        $this->call(ProductFrequencySeeder::class);
        $this->call(UserLevelSeeder::class);
    }
}

and execute "composer dump-autoload"

Now all the console commands works fine! I don't remember why I namespaced them, maybe some copypasta.

Thank you all for the help!

Please or to participate in this conversation.