diff --git a/app/Http/Controllers/Admin/FotoController.php b/app/Http/Controllers/Admin/FotoController.php index 67ffa7a..d302d8a 100755 --- a/app/Http/Controllers/Admin/FotoController.php +++ b/app/Http/Controllers/Admin/FotoController.php @@ -7,8 +7,7 @@ use App\Models\PaketFoto; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; -use Illuminate\Support\Facades\File; - +use Illuminate\Support\Facades\Storage; class FotoController extends Controller { @@ -61,9 +60,7 @@ public function store(Request $request) if ($request->hasFile('foto')) { $file = $request->file('foto'); $filename = time() . '_' . $file->getClientOriginalName(); - // Simpan langsung ke folder public untuk asset() - $file->move(public_path('img/foto'), $filename); - $path = 'img/foto/' . $filename; + $path = $file->storeAs('img/foto', $filename, 'public'); } PaketFoto::create([ @@ -114,15 +111,14 @@ public function update(Request $request, string $id) $data = $request->only(['nama', 'harga', 'durasi', 'deskripsi']); if ($request->hasFile('foto')) { - // Hapus file lama jika ada foto baru yang diunggah if ($paket->foto) { - File::delete(public_path($paket->foto)); + Storage::disk('public')->delete($paket->foto); } $file = $request->file('foto'); $filename = time() . '_' . $file->getClientOriginalName(); - $file->move(public_path('img/foto'), $filename); - $data['foto'] = 'img/foto/' . $filename; + $path = $file->storeAs('img/foto', $filename, 'public'); + $data['foto'] = $path; } $paket->update($data); @@ -135,12 +131,9 @@ public function destroy(string $id) // Cari data berdasarkan primary key id_paket $paket = PaketFoto::where('id_paket', $id)->firstOrFail(); - // 1. Cek dan hapus file foto dari folder public if ($paket->foto) { - File::delete(public_path($paket->foto)); + Storage::disk('public')->delete($paket->foto); } - - // 2. Hapus data dari database $paket->delete(); return redirect()->back()->with('success', 'Paket foto dan filenya berhasil dihapus!'); diff --git a/resources/views/admin/paket-foto/index.blade.php b/resources/views/admin/paket-foto/index.blade.php index f6344a4..22ec7e6 100755 --- a/resources/views/admin/paket-foto/index.blade.php +++ b/resources/views/admin/paket-foto/index.blade.php @@ -75,7 +75,7 @@ Rp {{ number_format($f->harga, 0, ',', '.') }} - Foto Produk diff --git a/resources/views/admin/paket-foto/partials/modal-create-foto.blade.php b/resources/views/admin/paket-foto/partials/modal-create-foto.blade.php index ee11b62..169b1d6 100755 --- a/resources/views/admin/paket-foto/partials/modal-create-foto.blade.php +++ b/resources/views/admin/paket-foto/partials/modal-create-foto.blade.php @@ -15,9 +15,9 @@
- + @error('nama')
{{ $message }}
@enderror @@ -27,12 +27,13 @@
- + placeholder="Harga Paket"value="{{ old('harga') }}">

Dalam Rupiah

- @error('nama') + @error('harga')
{{ $message }}
@enderror @@ -42,12 +43,13 @@
- + placeholder="Durasi Paket"value="{{ old('durasi') }}">

Dalam Menit

- @error('nama') + @error('durasi')
{{ $message }}
@enderror @@ -57,8 +59,8 @@
- + @error('deskripsi')
{{ $message }}
@enderror diff --git a/resources/views/admin/paket-foto/partials/modal-edit-foto.blade.php b/resources/views/admin/paket-foto/partials/modal-edit-foto.blade.php index 760118a..803d5c1 100755 --- a/resources/views/admin/paket-foto/partials/modal-edit-foto.blade.php +++ b/resources/views/admin/paket-foto/partials/modal-edit-foto.blade.php @@ -100,8 +100,8 @@ class="text-center text-muted d-none"> sini

-
diff --git a/resources/views/admin/paket-foto/partials/modal-show-foto.blade.php b/resources/views/admin/paket-foto/partials/modal-show-foto.blade.php index 1b08041..03bad15 100755 --- a/resources/views/admin/paket-foto/partials/modal-show-foto.blade.php +++ b/resources/views/admin/paket-foto/partials/modal-show-foto.blade.php @@ -12,8 +12,8 @@
@if ($f->foto) {{-- Langsung img tanpa wrapper --}} - + @else {{-- Div pengganti kalau tidak ada foto --}}