您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DocumentDefaultFactory.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\DocumentType;
  4. use App\Models\Setting\DocumentDefault;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. /**
  7. * @extends Factory<DocumentDefault>
  8. */
  9. class DocumentDefaultFactory extends Factory
  10. {
  11. /**
  12. * The name of the factory's corresponding model.
  13. *
  14. * @var string
  15. */
  16. protected $model = DocumentDefault::class;
  17. /**
  18. * Define the model's default state.
  19. *
  20. * @return array<string, mixed>
  21. */
  22. public function definition(): array
  23. {
  24. return [
  25. //
  26. ];
  27. }
  28. /**
  29. * The model's common default state.
  30. */
  31. private function baseState(DocumentType $type, string $prefix, string $header): array
  32. {
  33. return [
  34. 'type' => $type->value,
  35. 'number_prefix' => $prefix,
  36. 'header' => $header,
  37. 'item_name' => ['option' => 'items', 'custom' => null],
  38. 'unit_name' => ['option' => 'quantity', 'custom' => null],
  39. 'price_name' => ['option' => 'price', 'custom' => null],
  40. 'amount_name' => ['option' => 'amount', 'custom' => null],
  41. ];
  42. }
  43. /**
  44. * Indicate that the model's type is invoice.
  45. */
  46. public function invoice(): self
  47. {
  48. return $this->state($this->baseState(DocumentType::Invoice, 'INV-', 'Invoice'));
  49. }
  50. /**
  51. * Indicate that the model's type is bill.
  52. */
  53. public function bill(): self
  54. {
  55. return $this->state($this->baseState(DocumentType::Bill, 'BILL-', 'Bill'));
  56. }
  57. }