lists('id'); $secondIds = DB::table('{{second_table}}')->lists('id'); for($i = 0; $i < {{count}}; $i++) { DB::table('{{first_resource}}_{{second_resource}}')->insert([ '{{first_resource}}_id' => $faker->randomElement($firstIds), '{{second_resource}}_id' => $faker->randomElement($secondIds) ]); } } }