2
votes

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

2
Please can you detail the path/filename of the CategoriesTableSeeder class? - dparoli
database\seeds\CategoriesTableSeeder.php - Ekow
Hi @Ekow as @dparoli i see you don't write the use instruction try by adding thems. - pietro
Composer dump-autoload if you added it manually. I would recommend using artisan commands next time cause it does it for you. - Alex Mac
try to run composer dump-autoload , but it's strange it should'nt be needed in newest versions - dparoli

2 Answers

1
votes

I run Composer dump-autoload and voila! Worked as a charm. Also as suggested by Alex Mac, always generate Seeders with artisan commands.

1
votes

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.