You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DiscountFactory.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\DiscountComputation;
  4. use App\Enums\DiscountScope;
  5. use App\Enums\DiscountType;
  6. use App\Models\Setting\Discount;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Discount>
  10. */
  11. class DiscountFactory extends Factory
  12. {
  13. /**
  14. * The name of the factory's corresponding model.
  15. */
  16. protected $model = Discount::class;
  17. /**
  18. * Define the model's default state.
  19. *
  20. * @return array<string, mixed>
  21. */
  22. public function definition(): array
  23. {
  24. $startDate = $this->faker->dateTimeBetween('now', '+1 year');
  25. $endDate = $this->faker->dateTimeBetween($startDate, strtotime('+1 year'));
  26. return [
  27. 'description' => $this->faker->sentence,
  28. 'rate' => $this->faker->randomFloat(4, 0, 20),
  29. 'computation' => $this->faker->randomElement(DiscountComputation::class),
  30. 'scope' => $this->faker->randomElement(DiscountScope::class),
  31. 'start_date' => $startDate,
  32. 'end_date' => $endDate,
  33. 'enabled' => true,
  34. ];
  35. }
  36. public function salesDiscount(): self
  37. {
  38. return $this->state([
  39. 'name' => 'Summer Sale',
  40. 'type' => DiscountType::Sales,
  41. ]);
  42. }
  43. public function purchaseDiscount(): self
  44. {
  45. return $this->state([
  46. 'name' => 'Bulk Purchase',
  47. 'type' => DiscountType::Purchase,
  48. ]);
  49. }
  50. }