playing = new EloquentCollection(); $this->nextSong = new EloquentCollection(); $this->finished = new EloquentCollection(); $roomSession = $this->getRoomSession(session('room_code'))?->id ; if ($roomSession) { $this->roomSessionId = $roomSession->id; $this->loadSongs($this->roomSessionId); } } private function getRoomSession($apiToken): ?RoomSession { if (!$apiToken) return null; return RoomSession::where('api_token', $apiToken) ->whereIn('status', ['active', 'maintain']) ->first(); } public function refreshSongs() { if ($this->roomSessionId) { $this->loadSongs($this->roomSessionId); } } protected function loadSongs(string $roomSessionId) { $this->playing = OrderedSong::forSession($roomSessionId)->playing()->get(); $this->nextSong = OrderedSong::forSession($roomSessionId)->nextSong()->get(); $this->finished = OrderedSong::forSession($roomSessionId)->finished()->get(); } public function render() { return view('livewire.pages.ordered-song-list', [ 'playing' => $this->playing, 'nextSong' => $this->nextSong, 'finished' => $this->finished, ]); } }