3

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

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.