本文介绍了Laravel 5 - 工匠种子[ReflectionException]班SongsTableSeeder不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行 php artisan db:seed 时会收到以下错误:
When I run php artisan db:seed I am getting the following error:
[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
文件。
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
我刚刚测试过。它在Laravel 5中没有问题。
I've just tested it. It is working without a problem in Laravel 5
这篇关于Laravel 5 - 工匠种子[ReflectionException]班SongsTableSeeder不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!