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.9KB

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