diff --git a/app/Http/Controllers/Admin/Master/BarbershopController.php b/app/Http/Controllers/Admin/Master/BarbershopController.php index 4c685a2..80b8732 100644 --- a/app/Http/Controllers/Admin/Master/BarbershopController.php +++ b/app/Http/Controllers/Admin/Master/BarbershopController.php @@ -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 diff --git a/app/Http/Requests/Admin/Master/BarbershopRequest.php b/app/Http/Requests/Admin/Master/BarbershopRequest.php index c4dbfe3..1349c25 100644 --- a/app/Http/Requests/Admin/Master/BarbershopRequest.php +++ b/app/Http/Requests/Admin/Master/BarbershopRequest.php @@ -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'], ]; }