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.

CategoryFactory.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Setting\Category;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Category>
  7. */
  8. class CategoryFactory extends Factory
  9. {
  10. /**
  11. * The name of the factory's corresponding model.
  12. *
  13. * @var string
  14. */
  15. protected $model = Category::class;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition(): array
  22. {
  23. return [
  24. 'name' => $this->faker->word,
  25. 'type' => $this->faker->randomElement(['income', 'expense']),
  26. 'color' => $this->faker->hexColor,
  27. 'enabled' => false,
  28. ];
  29. }
  30. /**
  31. * Indicate that the category is of income type.
  32. */
  33. public function incomeCategory(string $name): self
  34. {
  35. return $this->state(function (array $attributes) use ($name) {
  36. return [
  37. 'name' => $name,
  38. 'type' => 'income',
  39. ];
  40. });
  41. }
  42. /**
  43. * Indicate that the category is of expense type.
  44. */
  45. public function expenseCategory(string $name): self
  46. {
  47. return $this->state(function (array $attributes) use ($name) {
  48. return [
  49. 'name' => $name,
  50. 'type' => 'expense',
  51. ];
  52. });
  53. }
  54. }