当我运行 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文件的同一目录中。
SongsTableSeeder
SongsTableSeeder.php
DatabaseSeeder.php
你需要在你的控制台中运行:
composer dump-autoload
生成新的类映射,然后运行:
php artisan db:seed
我刚刚测试过了。它在 Laravel 5 中没有问题