KTVCentral/app/Livewire/Forms/RoomGridForm.php

44 lines
1019 B
PHP
Raw Normal View History

<?php
namespace App\Livewire\Forms;
use App\Models\Room;
use App\Models\Branch;
use App\Enums\RoomType;
use Livewire\Component;
use Illuminate\Database\Eloquent\Collection;
class RoomGridForm extends Component
{
public $branchName="";
public array $roomTypes;
public function mount()
{
$this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(fn($e) => [$e->value => $e->labels()])->toArray();
}
public function render()
{
$branch = Branch::first();
$this->branchName = $branch->name ?? '';
$rooms = collect(); // 預設為空集合
$floors = [];
if ($branch) {
2025-07-24 11:54:13 +08:00
$rooms = Room::where('branch_id', $branch->id)->orderBy('name', 'asc')->get();
$floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
}
return view('livewire.forms.room-grid-form', [
'rooms' => $rooms,
'floors' => $floors,
]);
}
}