delete photo checking rule for edit and delete buket and foto

This commit is contained in:
LailaWulandarii 2026-01-07 17:06:39 +07:00
parent 30df8bbcf7
commit 9560793ff5
2 changed files with 6 additions and 6 deletions

View File

@ -122,7 +122,7 @@ public function update(Request $request, string $id)
if ($request->hasFile('foto')) {
// 1. Hapus foto lama jika ada
if ($buket->foto && file_exists(public_path($buket->foto))) {
if ($buket->foto) {
File::delete(public_path($buket->foto));
}
@ -142,7 +142,7 @@ public function destroy(string $id)
{
$buket = Buket::findOrFail($id);
if ($buket->foto && File::exists(public_path($buket->foto))) {
if ($buket->foto) {
File::delete(public_path($buket->foto));
}
$buket->delete();

View File

@ -29,7 +29,7 @@ public function store(Request $request)
$validator = Validator::make($request->all(), [
'nama' => 'required|string|min:3|max:100',
'harga' => 'required|numeric|min:0',
'durasi' => 'required|integer|min:1',
'durasi' => 'required|integer|min:0',
'deskripsi' => 'required|string|min:10',
'foto' => 'required|image|mimes:jpeg,png,jpg|max:2048',
], [
@ -84,7 +84,7 @@ public function update(Request $request, string $id)
$validator = Validator::make($request->all(), [
'nama' => 'required|string|min:3|max:100',
'harga' => 'required|numeric|min:0',
'durasi' => 'required|integer|min:1',
'durasi' => 'required|integer|min:0',
'deskripsi' => 'required|string|min:10',
'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
], [
@ -115,7 +115,7 @@ public function update(Request $request, string $id)
if ($request->hasFile('foto')) {
// Hapus file lama jika ada foto baru yang diunggah
if ($paket->foto && File::exists(public_path($paket->foto))) {
if ($paket->foto) {
File::delete(public_path($paket->foto));
}
@ -136,7 +136,7 @@ public function destroy(string $id)
$paket = PaketFoto::where('id_paket', $id)->firstOrFail();
// 1. Cek dan hapus file foto dari folder public
if ($paket->foto && File::exists(public_path($paket->foto))) {
if ($paket->foto) {
File::delete(public_path($paket->foto));
}