loadOutlets(); } protected function loadOutlets() { $this->outlets = Outlet::with(['openingHours', 'facilities']) ->when(! empty($this->search), fn ($query) => $query->where('name', 'like', '%'.$this->search.'%')) ->when(! empty($this->status), fn ($query) => $query->whereIn('status', $this->status)) ->latest() ->get() ->map(fn ($outlet) => [ 'hash' => $outlet->hash, 'name' => $outlet->name, 'phone_number' => $outlet->phone_number, 'landmark' => $outlet->landmark, 'address' => $outlet->address, 'status' => [ 'label' => $outlet->status->label(), 'color' => $outlet->status->color(), ], 'opening_hours' => $outlet->openingHours->mapWithKeys(fn ($hour) => [ Str::ucfirst(Str::lower(Day::from($hour->day->value)->label())) => [ 'open' => formatTime($hour->open_time), 'close' => formatTime($hour->close_time), 'is_closed' => $hour->open_time === null && $hour->close_time === null, ], ])->toArray(), 'facilities' => $outlet->facilities->pluck('name')->toArray(), 'opened_date' => formatDate($outlet->opened_date), 'opened_ago' => timeAgo($outlet->opened_date), 'closed_date' => formatDate($outlet->closed_date), 'closed_ago' => timeAgo($outlet->closed_date), 'image' => data_get($this->mapMediaCollection($outlet->getMedia('featured_image'))[0] ?? null, 'temporaryUrl', asset('assets/images/logo.png')), 'images' => collect($this->mapMediaCollection($outlet->getMedia('images')))->pluck('temporaryUrl')->filter()->values(), ]) ->toArray(); } public function updatedSearch(string $value) { $this->search = $value; $this->loadOutlets(); } public function updatedStatus() { $this->loadOutlets(); } public function openImage(string $imageUrl) { $this->imageUrl = $imageUrl; Flux::modal('image-modal')->show(); } public function delete(Outlet $outlet) { $outlet->delete(); $this->toast('Outlet berhasil dihapus.'); Flux::modals()->close(); } public function render() { return view('livewire.studio.master.outlet.index', [ 'pageTitle' => 'Outlet', ]); } }