ProductSKUFactory.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\MafOrder;
  4. use App\Models\Order;
  5. use App\Models\Product;
  6. use App\Models\ProductSKU;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<ProductSKU>
  10. */
  11. class ProductSKUFactory extends Factory
  12. {
  13. protected $model = ProductSKU::class;
  14. public function definition(): array
  15. {
  16. return [
  17. 'year' => (int) date('Y'),
  18. 'product_id' => Product::factory(),
  19. 'order_id' => Order::factory(),
  20. 'maf_order_id' => null,
  21. 'status' => 'needs',
  22. 'rfid' => fake()->optional()->numerify('RFID-########'),
  23. 'factory_number' => fake()->optional()->numerify('FN-######'),
  24. 'manufacture_date' => fake()->optional()->date(),
  25. 'statement_number' => null,
  26. 'statement_date' => null,
  27. 'upd_number' => null,
  28. 'comment' => fake()->optional()->sentence(),
  29. 'passport_id' => null,
  30. ];
  31. }
  32. public function withMafOrder(MafOrder $mafOrder = null): static
  33. {
  34. return $this->state(fn (array $attributes) => [
  35. 'maf_order_id' => $mafOrder?->id ?? MafOrder::factory(),
  36. 'status' => 'related',
  37. ]);
  38. }
  39. public function forOrder(Order $order): static
  40. {
  41. return $this->state(fn (array $attributes) => [
  42. 'order_id' => $order->id,
  43. ]);
  44. }
  45. public function forProduct(Product $product): static
  46. {
  47. return $this->state(fn (array $attributes) => [
  48. 'product_id' => $product->id,
  49. ]);
  50. }
  51. public function withAllDetails(): static
  52. {
  53. return $this->state(fn (array $attributes) => [
  54. 'rfid' => fake()->numerify('RFID-########'),
  55. 'factory_number' => fake()->numerify('FN-######'),
  56. 'manufacture_date' => fake()->date(),
  57. 'maf_order_id' => MafOrder::factory(),
  58. 'status' => 'related',
  59. ]);
  60. }
  61. }