| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace Database\Factories;
- use App\Models\Product;
- use App\Models\SparePart;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<SparePart>
- */
- class SparePartFactory extends Factory
- {
- protected $model = SparePart::class;
- public function definition(): array
- {
- return [
- 'article' => fake()->unique()->bothify('SP-####'),
- 'used_in_maf' => fake()->sentence(2),
- 'product_id' => null,
- 'note' => fake()->optional()->sentence(),
- 'purchase_price' => fake()->randomFloat(2, 100, 10000),
- 'customer_price' => fake()->randomFloat(2, 150, 15000),
- 'expertise_price' => fake()->randomFloat(2, 200, 20000),
- 'tsn_number' => fake()->optional()->numerify('TSN-####'),
- 'min_stock' => fake()->numberBetween(0, 10),
- ];
- }
- public function withProduct(): static
- {
- return $this->state(fn (array $attributes) => [
- 'product_id' => Product::factory(),
- ]);
- }
- public function withMinStock(int $minStock): static
- {
- return $this->state(fn (array $attributes) => [
- 'min_stock' => $minStock,
- ]);
- }
- }
|