protected function promotions(Product $product, $account) { $count = rand(1, 2); $counter = 0; while ($counter < $count) { $absolute = rand(0, 1); $dates = rand(0, 1); $product->promotionHistory()->save(new Promotion(['account_id' => $account, 'absolute' => $absolute, 'active_from' => $this->faker->dateTimeBetween('-3 years', '-5 months'), 'active_to' => $this->faker->dateTimeBetween('-5 months', '-2 days'), 'value' => $absolute ? rand(1, 5) * 10 : rand(1, 5 * 10 / 2), 'from' => $dates ? $this->faker->dateTimeBetween('-3 years', '-5 months') : null, 'to' => $dates ? $this->faker->dateTimeBetween('-5 months', '-2 days') : null])); $counter++; } if (rand(0, 1)) { $absolute = rand(0, 1); $dates = rand(0, 1); $product->promotion()->save(new ActivePromotion(['account_id' => $account, 'absolute' => $absolute, 'activated_on' => $this->faker->dateTimeBetween('-6 months', '-2 days'), 'value' => $absolute ? rand(1, 5) * 10 : rand(1, 5 * 10 / 2), 'from' => $dates ? $this->faker->dateTimeBetween('-3 years', '-5 months') : null, 'to' => $dates ? $this->faker->dateTimeBetween('-5 months', '-2 days') : null])); } }