SparePartFactory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Product;
  4. use App\Models\SparePart;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. /**
  7. * @extends Factory<SparePart>
  8. */
  9. class SparePartFactory extends Factory
  10. {
  11. protected $model = SparePart::class;
  12. public function definition(): array
  13. {
  14. return [
  15. 'article' => fake()->unique()->bothify('SP-####'),
  16. 'used_in_maf' => fake()->sentence(2),
  17. 'product_id' => null,
  18. 'note' => fake()->optional()->sentence(),
  19. 'purchase_price' => fake()->randomFloat(2, 100, 10000),
  20. 'customer_price' => fake()->randomFloat(2, 150, 15000),
  21. 'expertise_price' => fake()->randomFloat(2, 200, 20000),
  22. 'tsn_number' => fake()->optional()->numerify('TSN-####'),
  23. 'min_stock' => fake()->numberBetween(0, 10),
  24. ];
  25. }
  26. public function withProduct(): static
  27. {
  28. return $this->state(fn (array $attributes) => [
  29. 'product_id' => Product::factory(),
  30. ]);
  31. }
  32. public function withMinStock(int $minStock): static
  33. {
  34. return $this->state(fn (array $attributes) => [
  35. 'min_stock' => $minStock,
  36. ]);
  37. }
  38. }