Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection Exception : Class does not exist for manually added class

I added a seeder (copied from elsewhere and pasted) to my application and included the call in the Database Seeder run() function. I get the exception above even though the class exists.

I suspected that maybe some files may have been cached so i cleared the application cache but i still get the same error.

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);
    }
}

Seeder file 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(),
            ]
        ]);
    }
}

Error:

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

Any ideas on what might be causing this? Thanks in advance guys

like image 769
Ekow Avatar asked Feb 03 '26 09:02

Ekow


1 Answers

Whenever you create any new file, always run following commands :-

composer dumpa // composer dump-autoload
php artisan optimize:clear // php artisan optimize:clear 

because in bootstrap folder it keeps a track of each files and other configurations, etc.

like image 166
Vipertecpro Avatar answered Feb 04 '26 22:02

Vipertecpro