反射异常:Class 不存在手动添加的 class
Reflection Exception : Class does not exist for manually added class
我向我的应用程序添加了一个播种器(从其他地方复制并粘贴),并将调用包含在数据库播种器 运行() 函数中。即使 class 存在,我也会得到上面的异常。
我怀疑某些文件可能已被缓存,所以我清除了应用程序缓存,但我仍然遇到同样的错误。
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 : Class CategoriesTableSeeder does not exist
at C:\wamp\www\ma-sales-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
Exception trace:
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
关于可能导致此问题的任何想法?提前谢谢大家
I 运行 Composer dump-autoload 瞧!作为魅力工作。同样按照 Alex Mac 的建议,始终使用 artisan 命令生成播种机。
每当您创建任何新文件时,始终运行遵循以下命令:-
composer dumpa // composer dump-autoload
php artisan optimize:clear // php artisan optimize:clear
因为在 bootstrap 文件夹中它会跟踪每个文件和其他配置等。
我向我的应用程序添加了一个播种器(从其他地方复制并粘贴),并将调用包含在数据库播种器 运行() 函数中。即使 class 存在,我也会得到上面的异常。
我怀疑某些文件可能已被缓存,所以我清除了应用程序缓存,但我仍然遇到同样的错误。
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 : Class CategoriesTableSeeder does not exist
at C:\wamp\www\ma-sales-tracker\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
Exception trace:
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
关于可能导致此问题的任何想法?提前谢谢大家
I 运行 Composer dump-autoload 瞧!作为魅力工作。同样按照 Alex Mac 的建议,始终使用 artisan 命令生成播种机。
每当您创建任何新文件时,始终运行遵循以下命令:-
composer dumpa // composer dump-autoload
php artisan optimize:clear // php artisan optimize:clear
因为在 bootstrap 文件夹中它会跟踪每个文件和其他配置等。