find($entityId); if ($entity !== null && in_array($entity->type, ['switch', 'light'], true)) { app(DeviceCommandService::class)->toggle($entity); } } /** Persist a new tile order from the drag interaction. */ public function reorder(array $order): void { foreach (array_values($order) as $index => $uuid) { Entity::where('uuid', $uuid)->update(['panel_sort' => $index]); } } public function render() { $tiles = Entity::query() ->whereIn('type', ['switch', 'light']) ->where('panel_hidden', false) ->with('device.room', 'state') ->orderByRaw('panel_sort IS NULL, panel_sort') ->orderBy('id') ->get(); return view('livewire.panel', ['tiles' => $tiles]); } }