| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace Database\Factories;
- use App\Models\MafOrder;
- use App\Models\Order;
- use App\Models\Product;
- use App\Models\ProductSKU;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<ProductSKU>
- */
- class ProductSKUFactory extends Factory
- {
- protected $model = ProductSKU::class;
- public function definition(): array
- {
- return [
- 'year' => (int) date('Y'),
- 'product_id' => Product::factory(),
- 'order_id' => Order::factory(),
- 'maf_order_id' => null,
- 'status' => 'needs',
- 'rfid' => fake()->optional()->numerify('RFID-########'),
- 'factory_number' => fake()->optional()->numerify('FN-######'),
- 'manufacture_date' => fake()->optional()->date(),
- 'statement_number' => null,
- 'statement_date' => null,
- 'upd_number' => null,
- 'comment' => fake()->optional()->sentence(),
- 'passport_id' => null,
- ];
- }
- public function withMafOrder(MafOrder $mafOrder = null): static
- {
- return $this->state(fn (array $attributes) => [
- 'maf_order_id' => $mafOrder?->id ?? MafOrder::factory(),
- 'status' => 'related',
- ]);
- }
- public function forOrder(Order $order): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_id' => $order->id,
- ]);
- }
- public function forProduct(Product $product): static
- {
- return $this->state(fn (array $attributes) => [
- 'product_id' => $product->id,
- ]);
- }
- public function withAllDetails(): static
- {
- return $this->state(fn (array $attributes) => [
- 'rfid' => fake()->numerify('RFID-########'),
- 'factory_number' => fake()->numerify('FN-######'),
- 'manufacture_date' => fake()->date(),
- 'maf_order_id' => MafOrder::factory(),
- 'status' => 'related',
- ]);
- }
- }
|