96 lines
2.1 KiB
PHP
96 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Studio\Master;
|
|
|
|
use App\Livewire\Forms\Studio\Master\FormulaForm;
|
|
use App\Models\Bottle;
|
|
use App\Models\Formula as FormulaModel;
|
|
use App\Traits\WithAuthorization;
|
|
use App\Traits\WithCloseModal;
|
|
use App\Traits\WithConfirmation;
|
|
use App\Traits\WithToast;
|
|
use App\Traits\WithUpdatedData;
|
|
use Flux\Flux;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
#[Title('Rumus')]
|
|
class Formula extends Component
|
|
{
|
|
use WithAuthorization, WithCloseModal, WithConfirmation, WithToast, WithUpdatedData;
|
|
|
|
public FormulaForm $form;
|
|
|
|
public string $method = 'create';
|
|
|
|
public string $modalTitle = '';
|
|
|
|
public array $qualities = ['Premium', 'Super Premium', 'Murni'];
|
|
|
|
public array $sizes = [];
|
|
|
|
public function mount()
|
|
{
|
|
$this->sizes = Bottle::distinct()->orderBy('size')->pluck('size')->toArray();
|
|
}
|
|
|
|
#[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->setFormula(FormulaModel::byHashOrFail($id));
|
|
}
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->canOrAbort('create formula');
|
|
|
|
$this->form->store();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
$this->toast('Rumus berhasil ditambahkan.');
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$this->canOrAbort('update formula');
|
|
|
|
$this->form->update();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
$this->toast('Rumus berhasil diperbarui.');
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function delete(FormulaModel $formula)
|
|
{
|
|
$formula->delete();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
$this->toast('Rumus berhasil dihapus.');
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.studio.master.formulas', [
|
|
'pageTitle' => 'Rumus',
|
|
]);
|
|
}
|
|
}
|