ContractFactory.php 684 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Contract;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Contract>
  7. */
  8. class ContractFactory extends Factory
  9. {
  10. protected $model = Contract::class;
  11. public function definition(): array
  12. {
  13. return [
  14. 'year' => (int) date('Y'),
  15. 'contract_number' => fake()->unique()->bothify('CONTRACT-####-??'),
  16. 'contract_date' => fake()->dateTimeBetween('-1 year', 'now')->format('Y-m-d'),
  17. ];
  18. }
  19. public function forYear(int $year): static
  20. {
  21. return $this->state(fn (array $attributes) => [
  22. 'year' => $year,
  23. ]);
  24. }
  25. }