转自:https://www.sunzhongwei.com/laravel-db-seed-error-reflectionexception-class-xxx-does-not-exist
修改了 Laravel Backpack Settings 自带的 seeder 导入测试数据时,报错
php artisan db:seed --class=SettingsTableSeeder
[ReflectionException]
Class SettingsTableSeeder does not exist
解决方法
composer dump-autoload
dump-autoload 是 composer 的一个命令,与 laravel 无关。 其作用是重建 class map,即 laravel 项目需要用的 class 列表。
查看项目根目录下的 vendor/composer/autoload_classmap.php
可以看到
'Backpack\\Settings\\database\\seeds\\SettingsTableSeeder' => $vendorDir . '/backpack/settings/src/database/seeds/SettingsTableSeeder.php',
'SettingsTableSeeder' => $baseDir . '/database/seeds/SettingsTableSeeder.php',
也就是,去掉了内置的 SettingsTableSeeder 的 namespace 之后,会重新映射一个 class 出来。 而,如果继续保留原有的 namespace, 新修改的永远都不会生效
Warning: Ambiguous class resolution, "Backpack\Settings\database\seeds\SettingsTableSeeder" was found in both "/home/zhongwei/work/xxx/vendor/backpack/settings/src/database/seeds/SettingsTableSeeder.php" and "/home/zhongwei/work/xxx/database/seeds/SettingsTableSeeder.php", the first will be used.