fix(barbershop): memperbaiki logika update gambar

This commit is contained in:
Yoga Pangestu 2024-11-24 16:08:35 +07:00
parent 7a47675a37
commit f3422aad06
2 changed files with 9 additions and 3 deletions

View File

@ -58,7 +58,9 @@ public function update(Barbershop $barbershop, BarbershopRequest $request): Redi
DB::transaction(function () use ($barbershop, $validatedData) {
$barbershop->update($validatedData);
$this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $barbershop->id);
if (isset($validatedData['image'])) {
$this->uploadAttachment($validatedData['image'], 'barbershop', Barbershop::class, $barbershop->id);
}
});
notify()->success('Data berhasil ditambahkan', 'Berhasil');
@ -77,7 +79,7 @@ public function delete(Barbershop $barbershop): RedirectResponse
notify()->success('Data berhasil dihapus', 'Berhasil');
return redirect('dashboard/master/barbershop');
return back();
}
public function generateActionButtons(Barbershop $barbershop): string

View File

@ -25,6 +25,8 @@ protected function prepareForValidation(): void
public function rules(): array
{
$isEdit = $this->isMethod('put');
return [
'name' => ['required', 'string', 'max:50'],
'contact_number' => ['required', 'string', 'regex:/^\+?\d{10,15}$/'],
@ -33,7 +35,9 @@ public function rules(): array
'opened' => ['required', 'date'],
'closed' => ['nullable', 'date'],
'cash' => ['required', 'numeric', 'min:0', 'max:99999999.99'],
'image' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
'image' => $isEdit
? ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048']
: ['required', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
];
}