/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); //a real lesson id //a real tag id $lessonIds = Lesson::get()->lists('id')->all(); //returns an array of all lesson ids $tagIds = Tags::get()->lists('id')->all(); //returns an array of all tag ids foreach (range(1, 30) as $index) { //use query builder DB::table('lessons_tags')->insert(['lessons_id' => $faker->randomElement($lessonIds), 'tags_id' => $faker->randomElement($tagIds)]); } }