parfum/app/Livewire/Studio/Master/Outlet/Index.php
Yoga Pangestu 77bce6f0eb refactor(outlet): mengubah cara menampilkan data dari menggunakan datatable menjadi foreach card
-kasih pengecekan isset() ke form WithCloseModal
-menambahkan form atribute
-menghapus dispacth datatable, karena sudah tidak perlu
-kasih error untuk input fasilitas
2025-10-14 15:38:03 +07:00

85 lines
2.9 KiB
PHP

<?php
namespace App\Livewire\Studio\Master\Outlet;
use App\Enums\Day;
use App\Models\Outlet;
use App\Traits\WithCloseModal;
use App\Traits\WithConfirmation;
use App\Traits\WithMediaHandler;
use App\Traits\WithToast;
use Flux\Flux;
use Illuminate\Support\Str;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Outlet')]
class Index extends Component
{
use WithCloseModal, WithConfirmation, WithMediaHandler, WithToast;
public array $outlets = [];
public ?string $imageUrl = null;
public function mount()
{
$this->outlets = Outlet::with(['openingHours', 'facilities'])
->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' => $outlet->closed_date ? formatDate($outlet->closed_date) : null,
'closed_ago' => $outlet->closed_date ? timeAgo($outlet->closed_date) : null,
'edit_route' => route('studio.master.outlet.edit', $outlet->hash),
'delete_route' => route('studio.master.outlet.delete', $outlet->hash),
'image' => $this->mapMediaCollection($outlet->getMedia('featured_image'))[0]['temporaryUrl'],
'images' => collect($this->mapMediaCollection($outlet->getMedia('images')))->map(fn ($image) => $image['temporaryUrl']),
])
->toArray();
}
public function openImage(string $imageUrl)
{
$this->imageUrl = $imageUrl;
Flux::modal('image-modal')->show();
}
public function delete(Outlet $outlet)
{
$outlet->delete();
$this->dispatch('refreshDatatable');
$this->toast('Outlet berhasil dihapus.');
Flux::modals()->close();
}
public function render()
{
return view('livewire.studio.master.outlet.index', [
'pageTitle' => 'Outlet',
]);
}
}