subMinutes(10); // 所有房間 $rooms = Room::with('branch')->where('is_online',1)->get(); foreach ($rooms as $room) { $branch = optional($room->branch); $latestStatus = MachineStatus::where('hostname', $room->type->value.$room->name) ->latest('created_at') ->first(); if (!$latestStatus || $latestStatus->created_at < $threshold) { $room->is_online = false; $room->save(); $this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)"); } $response = (new MachineStatusForwarder( $branch->external_ip ?? '', '/api/room/receiveSwitch', $room->toArray() ))->forward(); } return 0; } }