parfum/app/Livewire/Studio/Feature/PerfumeFeature.php
Yoga Pangestu fb01f6ce6c feat(choose us & perfume feature): implementasi testing
- memperbaiki pemanggilan component karena sebelumnya dirubah path nya
- kasih return type
- kasih HasFactory doi model
2025-12-10 11:57:42 +07:00

104 lines
2.6 KiB
PHP

<?php
namespace App\Livewire\Studio\Feature;
use App\Livewire\Forms\Studio\Feature\PerfumeFeatureForm;
use App\Models\PerfumeFeature as PerfumeFeatureModel;
use App\Traits\Notification\WithSubscribeNotification;
use App\Traits\WithAuthorization;
use App\Traits\WithCloseModal;
use App\Traits\WithConfirmation;
use App\Traits\WithToast;
use App\Traits\WithUpdatedData;
use Flux\Flux;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Keunggulan Parfum')]
class PerfumeFeature extends Component
{
use WithAuthorization, WithCloseModal, WithConfirmation, WithSubscribeNotification, WithToast, WithUpdatedData;
public PerfumeFeatureForm $form;
public string $method = 'create';
public string $modalTitle = '';
public function create(): void
{
$this->canOrAbort('create perfume feature');
$this->form->store();
$this->dispatch('refreshDatatable');
$this->toast('Keunggulan parfum berhasil ditambahkan.');
Flux::modals()->close();
}
public function update(): void
{
$this->canOrAbort('update perfume feature');
$this->form->update();
$this->dispatch('refreshDatatable');
$this->toast('Keunggulan parfum berhasil diperbarui.');
Flux::modals()->close();
}
public function delete(PerfumeFeatureModel $perfumeFeature): void
{
$this->canOrAbort('delete perfume feature');
$this->form->perfumeFeature = $perfumeFeature;
$this->form->delete();
$this->dispatch('refreshDatatable');
$this->toast('Keunggulan parfum berhasil dihapus.');
Flux::modals()->close();
}
#[On('fn:sortOrder')]
public function sortOrder(PerfumeFeatureModel $perfumeFeature, string $direction): void
{
$this->canOrAbort('update perfume feature');
$this->form->perfumeFeature = $perfumeFeature;
$this->form->sortOrder($direction);
$this->dispatch('refreshDatatable');
}
#[On('modal:open')]
public function openModal(string $method, string $modalTitle, ?string $id = null): void
{
$this->resetValidation();
$this->resetErrorBag();
$this->method = $method;
$this->modalTitle = $modalTitle;
if ($id) {
$this->form->setPerfumeFeature(PerfumeFeatureModel::byHashOrFail($id));
}
}
public function render(): View
{
return view('livewire.studio.feature.perfume-features', [
'pageTitle' => 'Keunggulan Parfum',
]);
}
}