1

I made base upon documentation a Database migration named class GridWithRoverSeeder in ./database/seeds/GridWithRoverSeeder.php:

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class GridWithRoverSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('grid')->insert([
            'id' => 1,
            'width' => 10,
            'height' => 10,
        ]);

        DB::table('rover')->insert([
            'id' => 1,
            'rover_id' => 1,
            'command' => "RRMRMMRM",
            'last_command'=>""
        ]);
    }
}

And I call it from DatabaseSeeder:

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            GridWithRoverSeeder::class
        ]);
    }
}

But when I run php artisan db:seed I get the following error:

   ReflectionException  : Class GridWithRoverSeeder does not exist

Do you have any idea why?

halfer
  • 19,824
  • 17
  • 99
  • 186
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164

2 Answers2

4

I was able to recreate your problem and this helped fix it.

Delete your seeder file and regenerate it.

php artisan make:seed GridWithRoverSeeder

Run

composer dump-autoload

Call the seeder in DatabaseSeeder

$this->call([
        GridWithRoverSeeder::class
    ]);

Note: Avoid renaming the file manually.

shahburhan
  • 224
  • 1
  • 12
  • What's different here from my answer? – Vikash Pathak Jun 20 '19 at 17:54
  • Did you identified the caused? @shahburhan – Vikash Pathak Jun 20 '19 at 17:55
  • Not a good approach to stolen the answer of other person and just paste after some unnecessary modifications – Vikash Pathak Jun 20 '19 at 17:56
  • We are all here to help. Doesn't matter which answer is selected as long as it actually solves the problem. If autoload dump alone would have solved the problem he would have selected your answer already even before I posted another solution. Peace. – shahburhan Jun 20 '19 at 18:47
  • I appreciate it if having some different approach! I'm not about the ans selected. But what you have learnt /perposed new here? – Vikash Pathak Jun 20 '19 at 19:11
  • The file deletion is unessesary. – Dimitrios Desyllas Jun 21 '19 at 09:41
  • He had done everything correct. The only reason i thought to be the issue is he possibly renamed the file without renaming the class. And that's how he got it to fix. That's why I asked him to re generate the file. Even autoload dump isnt neccessary all the time. I don't know what all the fuss is about. He got it to work with this solution. autoload-dump alone didnt fix his problem – shahburhan Jun 21 '19 at 11:32
  • Yes... the file deletion was not required... only the single command `composer dump-autoload` should fix the issue... it's left user in dark without know the actual reason. – Vikash Pathak Jun 21 '19 at 11:52
1

Make sure you have run composer dump-autoload after creating seeder or any new class in laravel.

Vikash Pathak
  • 3,444
  • 1
  • 18
  • 32