feat(formula): menambahkan pengecekan duplikasi data
- menyesuaikan tampilan - role admin bias lihat rumus - memberikan validasi untuk volume tidak boleh lebih besar dari size
This commit is contained in:
parent
9a5a7661da
commit
4d51e7b20c
@ -21,7 +21,7 @@ public function rules(): array
|
|||||||
return [
|
return [
|
||||||
'quality' => ['required', 'string', 'max:20'],
|
'quality' => ['required', 'string', 'max:20'],
|
||||||
'size' => ['required', new UnsignedInteger],
|
'size' => ['required', new UnsignedInteger],
|
||||||
'volume' => ['required', new UnsignedInteger],
|
'volume' => ['required', 'lte:size', new UnsignedInteger],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,15 +34,19 @@ class Formula extends Component
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
$this->formulas = FormulaModel::orderBy('size')->get()
|
$this->formulas = FormulaModel::orderBy('size')
|
||||||
|
->get()
|
||||||
->groupBy('size')
|
->groupBy('size')
|
||||||
->map(function ($items) {
|
->map(function ($items) {
|
||||||
return $items->map(fn ($item) => [
|
return $items
|
||||||
'hash' => $item->hash,
|
->map(fn ($item) => [
|
||||||
'quality' => $item->quality,
|
'hash' => $item->hash,
|
||||||
'volume' => $item->volume,
|
'quality' => $item->quality,
|
||||||
]);
|
'volume' => $item->volume,
|
||||||
})->toArray();
|
])
|
||||||
|
->sortBy('volume');
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
|
||||||
$this->sizes = Bottle::distinct()->orderBy('size')->pluck('size')->toArray();
|
$this->sizes = Bottle::distinct()->orderBy('size')->pluck('size')->toArray();
|
||||||
}
|
}
|
||||||
@ -63,6 +67,12 @@ public function openModal(string $method, string $modalTitle, ?string $id = null
|
|||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
if (FormulaModel::where('quality', $this->form->quality)->where('size', $this->form->size)->exists()) {
|
||||||
|
$this->toast('Rumus dengan kualitas dan ukuran tersebut sudah ada.', 'Info', 'warning');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->canOrAbort('create formula');
|
$this->canOrAbort('create formula');
|
||||||
|
|
||||||
$formula = $this->form->store();
|
$formula = $this->form->store();
|
||||||
@ -83,6 +93,17 @@ public function create()
|
|||||||
|
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
|
$exists = FormulaModel::where('quality', $this->form->quality)
|
||||||
|
->where('size', $this->form->size)
|
||||||
|
->where('id', '!=', $this->form->formula->id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
|
$this->toast('Rumus dengan kualitas dan ukuran tersebut sudah ada.', 'Info', 'warning');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->canOrAbort('update formula');
|
$this->canOrAbort('update formula');
|
||||||
|
|
||||||
$formula = $this->form->update();
|
$formula = $this->form->update();
|
||||||
|
|||||||
@ -287,7 +287,6 @@ public function run(): void
|
|||||||
'delete user',
|
'delete user',
|
||||||
'reset password user',
|
'reset password user',
|
||||||
|
|
||||||
'view formula',
|
|
||||||
'create formula',
|
'create formula',
|
||||||
'update formula',
|
'update formula',
|
||||||
'delete formula',
|
'delete formula',
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
@if (!empty($formulas))
|
@if (!empty($formulas))
|
||||||
<div class="mt-6 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
<div class="mt-6 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 items-start">
|
||||||
@foreach ($formulas as $key => $formula)
|
@foreach ($formulas as $key => $formula)
|
||||||
<flux:card class="space-y-2">
|
<flux:card class="space-y-2">
|
||||||
<div class="mb-4 pb-3 border-b border-gray-200">
|
<div class="mb-4 pb-3 border-b border-gray-200">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user