当我运行php artisan db:seed时,出现以下错误:
[ReflectionException] Class SongsTableSeeder does not exist
到底是怎么回事?
我的DatabaseSeeder类:
<?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');
}
}
我的SongsTableSeeder类:
<?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);
}
}
最佳答案
您需要将SongsTableSeeder
放入文件SongsTableSeeder.php
中与您的DatabaseSeeder.php
文件相同的目录中。
并且您需要在控制台中运行:
composer dump-autoload
生成新的类映射,然后运行:
php artisan db:seed
我刚刚测试过。它在Laravel 5中正常工作