*/ class OrderItemFactory extends Factory { protected $model = OrderItem::class; /** * Define the model's default state. * * @return array */ public function definition(): array { $qty = $this->faker->numberBetween(1, 10); $price = $this->faker->numberBetween(50000, 200000); return [ 'user_id' => User::inRandomOrder()->first()?->id ?? User::factory(), 'order_id' => Order::factory(), 'product_id' => Product::inRandomOrder()->first()?->id ?? Product::factory(), 'price' => $price, 'qty' => $qty, 'total' => $price * $qty, 'price_type' => $this->faker->randomElement(PriceType::cases()), ]; } }