【发布时间】:2020-01-03 18:20:37
【问题描述】:
我在我的应用程序中添加了一个播种器(从其他地方复制并粘贴),并将调用包含在 Database Seeder 的 run() 函数中。即使该类存在,我也会遇到上述异常。
我怀疑某些文件可能已被缓存,因此我清除了应用程序缓存,但仍然遇到相同的错误。
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
// $this->call(CustomersTableSeeder::class);
$this->call(RolesTableSeeder::class);
$this->call(ManagerStatesTableSeeder::class);
$this->call(ManagersTableSeeder::class);
$this->call(CountsTableSeeder::class);
$this->call(CategoriesTableSeeder::class);
}
}
种子文件 CategoriesTableSeeder.php
<?php
use Illuminate\Database\Seeder;
class CategoriesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
\DB::table('categories')->insert([
[
'description' => 'Perfumes and Deo',
'slug' => 'perfumes-and-deo',
'parent' => 0,
'level' => 1,
'cna' => '2|',
'created_at' => \Carbon\Carbon::now(),
'updated_at' => \Carbon\Carbon::now(),
],
[
'description' => 'Perfumes',
'slug' => 'perfumes',
'parent' => 1,
'level' => 2,
'cna' => NULL,
'created_at' => \Carbon\Carbon::now(),
'updated_at' => \Carbon\Carbon::now(),
]
]);
}
}
错误:
ReflectionException : 类 CategoriesTableSeeder 不存在
在 C:\wamp\www\ma-sales-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
异常跟踪:
1 ReflectionClass::__construct("CategoriesTableSeeder") C:\wamp\www\ma-sales-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
2 Illuminate\Container\Container::build("CategoriesTableSeeder") C:\wamp\www\ma-sales-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:667
关于可能导致此问题的任何想法?先谢谢各位了
【问题讨论】:
-
能否详细说明 CategoriesTableSeeder 类的路径/文件名?
-
数据库\seeds\CategoriesTableSeeder.php
-
嗨@Ekow as @dparoli 我看到你没有写
use指令尝试添加它们。 -
Composer dump-autoload 如果您手动添加它。我建议下次使用工匠命令,因为它会为您完成。
-
尝试运行 composer dump-autoload ,但奇怪的是最新版本不需要它
标签: php laravel laravel-5.8