php 实现数据透视表,php – 如何在Laravel 5.4中播放数据透视表?

我正在跟随Jeffrey Way在laracasts中使用名为Incremental API的教程.

Laravel 4 faker类播种和laravel 5.4之间有不同的编码.

我仍然遵循教程“Seeders Reloaded”中的相同代码行.现在,我被困在“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)

]);

}

}

DatabaseSeeder

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”时,系统会提示我:

[ReflectionException]

Class LessonTagTableSeeder不存在

你知道如何编辑上面的代码吗?任何帮助表示赞赏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值