Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CategoryFactory.php 1.4KB

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