KTVCentral/app/Livewire/Pages/OrderedSongList.php

49 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Pages;
use Livewire\Component;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use App\Models\RoomSession;
use App\Models\OrderedSong;
class OrderedSongList extends Component
{
public $roomSession;
public EloquentCollection $playing ;
public EloquentCollection $nextSong ;
public EloquentCollection $finished ;
public function mount()
{
$this->playing = new EloquentCollection();
$this->nextSong = new EloquentCollection();
$this->finished = new EloquentCollection();
$this->roomSession = request()->roomSession;
$this->refreshSongs();
}
public function refreshSongs()
{
$dbSession = $this->roomSession->refreshValid();
if (!$dbSession) {
session()->forget('room_code');
return $this->redirect(route('welcome'), navigate: true);
}
$this->playing = OrderedSong::forSession($this->roomSession->id)->playing()->get();
$this->nextSong = OrderedSong::forSession($this->roomSession->id)->nextSong()->get();
$this->finished = OrderedSong::forSession($this->roomSession->id)->finished()->get();
}
public function render()
{
return view('livewire.pages.ordered-song-list', [
'playing' => $this->playing,
'nextSong' => $this->nextSong,
'finished' => $this->finished,
]);
}
}