Try adding app/Database/Seeds to your autoload:
"classmap": [
"database/migrations",
"database/seeds",
"app/Database/Seeds"
],
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
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.
Please or to participate in this conversation.