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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Setting\Discount;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Discount>
  7. */
  8. class DiscountFactory extends Factory
  9. {
  10. /**
  11. * The name of the factory's corresponding model.
  12. *
  13. * @var string
  14. */
  15. protected $model = Discount::class;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition(): array
  22. {
  23. // Common fields
  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(Discount::getComputationTypes()),
  30. 'scope' => $this->faker->randomElement(Discount::getDiscountScopes()),
  31. 'start_date' => $startDate,
  32. 'end_date' => $endDate,
  33. 'enabled' => true,
  34. ];
  35. }
  36. public function salesDiscount(): self
  37. {
  38. return $this->state(function (array $attributes) {
  39. return [
  40. 'name' => 'Summer Sale',
  41. 'type' => 'sales',
  42. ];
  43. });
  44. }
  45. public function purchaseDiscount(): self
  46. {
  47. return $this->state(function (array $attributes) {
  48. return [
  49. 'name' => 'Bulk Purchase',
  50. 'type' => 'purchase',
  51. ];
  52. });
  53. }
  54. }