KTV/app/Livewire/Grids/RoomGrid.php
allen.yan 2769e82a37 功能調整
API 收到包廂指令先押資料
加入 包廂列表
加入 包廂控制介面
加入 包廂記錄
補上正規劃
20250729
2025-07-29 00:24:03 +08:00

47 lines
1.2 KiB
PHP

<?php
namespace App\Livewire\Grids;
use App\Models\Room;
use App\Models\Branch;
use App\Enums\RoomType;
use Livewire\Component;
use Illuminate\Database\Eloquent\Collection;
class RoomGrid extends Component
{
public ?int $selectedBranchId = null;
public string $external_ip= "";
public array $roomTypes;
public function mount()
{
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(
fn($e) => [$e->value => $e->labels()]
)->toArray();
$this->selectChanged(Branch::first()->id,"","");
}
public function selectChanged($value,$fieldName, $modelId): void
{
$branch = $value ? Branch::find($value) : null;
$this->selectedBranchId=$branch?->id ?? '';
$this->external_ip = $branch?->external_ip ?? '';
}
public function render()
{
$rooms = Room::where('branch_id', $this->selectedBranchId)->orderBy('name')->get();
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
return view('livewire.grids.room-grid', [
'rooms' => $rooms,
'floors' => $floors,
]);
}
}