Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DiscountFactory.php 1.4KB

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