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 [
|
||||
'quality' => ['required', 'string', 'max:20'],
|
||||
'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()
|
||||
{
|
||||
$this->formulas = FormulaModel::orderBy('size')->get()
|
||||
$this->formulas = FormulaModel::orderBy('size')
|
||||
->get()
|
||||
->groupBy('size')
|
||||
->map(function ($items) {
|
||||
return $items->map(fn ($item) => [
|
||||
'hash' => $item->hash,
|
||||
'quality' => $item->quality,
|
||||
'volume' => $item->volume,
|
||||
]);
|
||||
})->toArray();
|
||||
return $items
|
||||
->map(fn ($item) => [
|
||||
'hash' => $item->hash,
|
||||
'quality' => $item->quality,
|
||||
'volume' => $item->volume,
|
||||
])
|
||||
->sortBy('volume');
|
||||
})
|
||||
->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()
|
||||
{
|
||||
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');
|
||||
|
||||
$formula = $this->form->store();
|
||||
@ -83,6 +93,17 @@ public function create()
|
||||
|
||||
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');
|
||||
|
||||
$formula = $this->form->update();
|
||||
|
||||
@ -287,7 +287,6 @@ public function run(): void
|
||||
'delete user',
|
||||
'reset password user',
|
||||
|
||||
'view formula',
|
||||
'create formula',
|
||||
'update formula',
|
||||
'delete formula',
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
<div class="mt-6">
|
||||
@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)
|
||||
<flux:card class="space-y-2">
|
||||
<div class="mb-4 pb-3 border-b border-gray-200">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user