-membuat model, migrasi seeder dan faker -membuat relasi di user -membuat test untuk memastikan jalannya aplikasi
94 lines
2.0 KiB
PHP
94 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Studio\Loyalty;
|
|
|
|
use App\Livewire\Forms\CustomerForm;
|
|
use App\Models\Customer as CustomerModel;
|
|
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('Customer')]
|
|
class Customer extends Component
|
|
{
|
|
use WithCloseModal, WithConfirmation, WithUpdatedData;
|
|
|
|
public CustomerForm $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->setCustomer(CustomerModel::findOrFail($id));
|
|
}
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->form->store();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
Flux::toast(
|
|
heading: 'Berhasil',
|
|
text: 'Customer berhasil ditambahkan.',
|
|
variant: 'success',
|
|
duration: 3000
|
|
);
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$this->form->update();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
Flux::toast(
|
|
heading: 'Berhasil',
|
|
text: 'Customer berhasil diperbarui.',
|
|
variant: 'success',
|
|
duration: 3000
|
|
);
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function delete(CustomerModel $customer)
|
|
{
|
|
$customer->delete();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
Flux::toast(
|
|
heading: 'Berhasil',
|
|
text: 'Customer berhasil dihapus.',
|
|
variant: 'success',
|
|
);
|
|
|
|
Flux::modals()->close();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.studio.loyalty.customers', [
|
|
'pageTitle' => 'Customer',
|
|
]);
|
|
}
|
|
}
|