isEmpty() || $tables->isEmpty() || $customers->isEmpty() || $paymentMethods->isEmpty()) { $this->command->warn('⚠️ Missing related data (foods, tables, customers, or payment methods). Seeder skipped.'); return; } foreach (range(1, 100) as $i) { // Pick a random order date within the last 30 days $orderDate = Carbon::now()->subDays(rand(0, 29))->setTime(rand(10, 22), [0, 30][rand(0, 1)]); // Create main order $order = Order::create([ 'restaurant_id' => 1, 'order_type' => collect(['dine_in', 'takeaway', 'delivery'])->random(), 'order_number' => 'ORD-'.$orderDate->format('Ymd').'-'.rand(1000, 99999), 'status' => collect(['pending', 'completed', 'cancelled'])->random(), 'order_date' => $orderDate, 'table_id' => $tables->random()->id, 'payment_method_id' => $paymentMethods->random()->id, 'payment_status' => collect([0, 1])->random(), 'waiter_id' => $waiter?->id, 'customer_id' => $customers->random()->id, 'grand_total' => 0, ]); // Add random items $total = 0; foreach ($foods->random(rand(1, 3)) as $food) { $qty = rand(1, 2); $price = $food->price ?? 100; $lineTotal = $qty * $price; OrderItem::create([ 'restaurant_id' => 1, 'order_id' => $order->id, 'food_item_id' => $food->id, 'quantity' => $qty, 'price' => $price, 'total' => $lineTotal, ]); $total += $lineTotal; } $order->update(['grand_total' => $total]); } $this->command->info('✅ 100 random orders seeded successfully (within the last 30 days).'); } }