parfum/app/Livewire/Studio/Catalog/Brand.php
2025-09-29 20:02:06 +07:00

106 lines
2.2 KiB
PHP

<?php
namespace App\Livewire\Studio\Catalog;
use App\Livewire\Forms\BrandForm;
use App\Models\Brand as BrandModel;
use App\Traits\WithCloseModal;
use App\Traits\WithConfirmation;
use App\Traits\WithUpdatedData;
use Flux\Flux;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Merek')]
class Brand extends Component
{
use WithCloseModal, WithConfirmation, WithUpdatedData;
public BrandForm $form;
public string $method = 'create';
public string $modalTitle = '';
#[On('modal:open')]
public function openModal(string $method, string $modalTitle, ?string $id = null)
{
$this->resetValidation();
$this->resetErrorBag();
$this->method = $method;
$this->modalTitle = $modalTitle;
if ($id) {
$this->form->setBrand(BrandModel::findOrFail($id));
}
}
public function create()
{
$this->form->store();
$this->dispatch('refreshDatatable');
Flux::toast(
heading: 'Berhasil',
text: 'Merek berhasil ditambahkan.',
variant: 'success',
duration: 3000
);
Flux::modals()->close();
}
public function update()
{
$this->form->update();
$this->dispatch('refreshDatatable');
Flux::toast(
heading: 'Berhasil',
text: 'Merek berhasil diperbarui.',
variant: 'success',
duration: 3000
);
Flux::modals()->close();
}
public function delete(BrandModel $brand)
{
$this->form->brand = $brand;
$this->form->delete();
$this->dispatch('refreshDatatable');
Flux::toast(
heading: 'Berhasil',
text: 'Merek berhasil dihapus.',
variant: 'success',
);
Flux::modals()->close();
}
#[On('fn:sortOrder')]
public function sortOrder(BrandModel $brand, string $direction)
{
$this->form->brand = $brand;
$this->form->sortOrder($direction);
$this->dispatch('refreshDatatable');
}
public function render()
{
return view('livewire.studio.catalog.brands', [
'pageTitle' => 'Merek',
]);
}
}