loadValues('proyecto', columns: 'id'); $data = []; $count = $this->faker->numberBetween(1, 10); for ($i = 0; $i < $count; $i++) { $start = $this->faker->dateTimeBetween('-1 year'); $end = $this->faker->dateTimeBetween($start, $start->add(new DateInterval('P1Y'))); $data[] = [ 'description' => $this->faker->sentence, 'type' => 1, 'amount' => $this->faker->randomFloat(2, 0, 1), 'start_date' => $start, 'end_date' => $end, 'valid_until' => $this->faker->dateTimeBetween($end, $end->add(new DateInterval('P1M'))), 'state' => 1, ]; } $this->table('promotions')->insertValues($data)->save(); $promotions = $this->loadValues('promotions', columns: 'id'); $data = []; foreach ($projects as $project) { $hasPromo = $this->faker->boolean(10); if (!$hasPromo) { continue; } $data []= [ 'promotion_id' => $this->faker->randomElement($promotions), 'project_id' => $project, ]; } if (count($data) > 0) { $this->table('promotion_projects')->insertValues($data)->save(); } } }