When I run php artisan db:seed I am getting the following error:
[ReflectionException] Class SongsTableSeeder does not exist
What is going on?
My DatabaseSeeder class:
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call('SongsTableSeeder');
}
}
My SongsTableSeeder class:
<?php
// Composer: "fzaninotto/faker": "v1.4.0"
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
use DB;
class SongsTableSeeder extends Seeder {
public function run()
{
$faker = Faker::create();
$songs = [];
foreach(range(1, 10) as $index)
{
$songs[] = ['title' => $faker->words(rand(1,4))];
}
DB::table('songs')->insert($songs);
}
}
You need to put SongsTableSeeder
into file SongsTableSeeder.php
in the same directory where you have your DatabaseSeeder.php
file.
And you need to run in your console:
composer dump-autoload
to generate new class map and then run:
php artisan db:seed
I've just tested it. It is working without a problem in Laravel 5
I solved it by doing this:
This happened because I made a change in the filename. I don't know why it didn't work after the change.
File SongsTableSeeder.php should be in database/seeds directory or in its subdirectory.
You need to run:
composer dump-autoload
and then:
php artisan db:seed
or:
php artisan db:seed --class=SongsTableSeeder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With