【发布时间】:2017-09-19 03:47:33
【问题描述】:
我正在学习 Jeffrey Way 的 laracasts 中的增量 API 教程。
在 Laravel 4 faker 类播种和 laravel 5.4 之间存在不同的编码。
我仍然遵循教程“重载播种机”中的相同代码行。现在,我被“Class LessonTagTableSeeder 不存在”所困
TagTableSeeder
class TagsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create('App\Tag');
for($i=1; $i <= 10; $i++) {
DB::table('tags')->insert([
'name' => $faker->word,
'created_at' => \Carbon\Carbon::now(),
'updated_at' => \Carbon\Carbon::now(),
]);
}
}
LessonTagTableSeeder
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
use App\Lesson;
use App\Tag;
class LessonTagTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
$lessonIds = Lesson::pluck('id')->all();
$tagIds = Tag::pluck('id')->all();
for($i=1; $i <= 30; $i++) {
DB::table('lesson_tag')->insert([
'lesson_id' => $faker->randomElement($lessonIds),
'tag_id' => $faker->randomElement($tagIds)
]);
}
}
数据库播种器
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Lesson;
use App\Tag;
use DB;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0');
Lesson::truncate();
Tag::truncate();
DB::table('lesson_tag')->truncate();
Model::unguard();
$this->call('LessonsTableSeeder');
$this->call('TagsTableSeeder');
$this->call('LessonTagTableSeeder');
DB::statement('SET FOREIGN_KEY_CHECKS=1');
}
我能够使用 php artisan db:seed --class=TagsTableSeeder
为 TagsTableSeeder 播种当我运行 "php artisan db:seed --class=LessonTagTableSeeder" 时,系统提示我:
[反射异常] 类 LessonTagTableSeeder 不存在
你知道如何编辑上面的代码吗?任何帮助表示赞赏
【问题讨论】: