diff --git a/.env.example b/.env.example index 35db1dd..21a7a15 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ APP_NAME=Laravel APP_ENV=local -APP_KEY= +APP_KEY=base64:z0LwGs8KEUKLZiscpb4+KURGPLdoVKo4L6YoGqB40uE= APP_DEBUG=true APP_URL=http://localhost @@ -20,14 +20,14 @@ LOG_STACK=single LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug -DB_CONNECTION=sqlite -# DB_HOST=127.0.0.1 -# DB_PORT=3306 -# DB_DATABASE=laravel -# DB_USERNAME=root -# DB_PASSWORD= +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=smk_nasional +DB_USERNAME=root +DB_PASSWORD= -SESSION_DRIVER=database +SESSION_DRIVER=file SESSION_LIFETIME=120 SESSION_ENCRYPT=false SESSION_PATH=/ @@ -35,6 +35,10 @@ SESSION_DOMAIN=null BROADCAST_CONNECTION=log FILESYSTEM_DISK=local + +# Path untuk penyimpanan di hosting (di luar project) +STORAGE_PATH=/home/kubgnmev/public_html/penyimpanan +STORAGE_URL=/penyimpanan QUEUE_CONNECTION=database CACHE_STORE=database diff --git a/app/Helpers.php b/app/Helpers.php new file mode 100644 index 0000000..68c63d5 --- /dev/null +++ b/app/Helpers.php @@ -0,0 +1,15 @@ +validate([ - 'judul_lowongan' => 'required|string|max:255', - 'nama_perusahaan' => 'required|string|max:255', - 'persyaratan' => 'required|string', - 'tanggal_dibuka' => 'required|date', - 'tanggal_ditutup' => 'required|date|after_or_equal:tanggal_dibuka', - 'foto' => 'required|image|mimes:jpg,jpeg,png,gif,bmp,webp', - ]); - - $data = $request->all(); + { + $request->validate([ + 'judul_lowongan' => 'required|string|max:255', + 'nama_perusahaan' => 'required|string|max:255', + 'persyaratan' => 'required|string', + 'tanggal_dibuka' => 'required|date', + 'tanggal_ditutup' => 'required|date|after_or_equal:tanggal_dibuka', + 'foto' => 'required|image|mimes:jpg,jpeg,png,gif,bmp,webp', + ]); + + $data = $request->all(); + $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); - $data['id_user'] = Auth::id(); + // Handle upload foto - SIMPAN KE folder penyimpanan eksternal + if ($request->hasFile('foto')) { + if (!file_exists($storagePath . '/foto_bkk')) { + mkdir($storagePath . '/foto_bkk', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_bkk', $filename); + $data['foto'] = 'foto_bkk/' . $filename; + } - // Handle upload foto - SIMPAN LANGSUNG KE public/storage - if ($request->hasFile('foto')) { - $filename = time() . '_' . $request->file('foto')->getClientOriginalName(); - $request->file('foto')->move(public_path('storage/foto_bkk'), $filename); - $data['foto'] = 'foto_bkk/' . $filename; + Bkk::create($data); + + return redirect()->route('bkk.index')->with('success', 'Data BKK berhasil ditambahkan.'); } - - Bkk::create($data); - - return redirect()->route('bkk.index')->with('success', 'Data BKK berhasil ditambahkan.'); -} /** * Display the specified resource for public view. */ @@ -82,36 +92,42 @@ public function edit(Bkk $bkk) * Update the specified resource in storage. */ public function update(Request $request, $id_bkk) -{ - $bkk = Bkk::findOrFail($id_bkk); + { + $bkk = Bkk::findOrFail($id_bkk); - $request->validate([ - 'judul_lowongan' => 'required|string|max:255', - 'nama_perusahaan' => 'required|string|max:255', - 'persyaratan' => 'required|string', - 'tanggal_dibuka' => 'required|date', - 'tanggal_ditutup' => 'required|date|after_or_equal:tanggal_dibuka', - 'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif,bmp,webp', - ]); + $request->validate([ + 'judul_lowongan' => 'required|string|max:255', + 'nama_perusahaan' => 'required|string|max:255', + 'persyaratan' => 'required|string', + 'tanggal_dibuka' => 'required|date', + 'tanggal_ditutup' => 'required|date|after_or_equal:tanggal_dibuka', + 'foto' => 'nullable|image|mimes:jpg,jpeg,png,gif,bmp,webp', + ]); - $data = $request->all(); + $data = $request->all(); + + $storagePath = $this->storagePath(); - // Handle upload foto baru - if ($request->hasFile('foto')) { - // Hapus foto lama jika ada - if ($bkk->foto && file_exists(public_path('storage/' . $bkk->foto))) { - unlink(public_path('storage/' . $bkk->foto)); + // Handle upload foto baru + if ($request->hasFile('foto')) { + // Hapus foto lama jika ada + if ($bkk->foto && file_exists($storagePath . '/' . $bkk->foto)) { + unlink($storagePath . '/' . $bkk->foto); + } + + if (!file_exists($storagePath . '/foto_bkk')) { + mkdir($storagePath . '/foto_bkk', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_bkk', $filename); + $data['foto'] = 'foto_bkk/' . $filename; + } else { + unset($data['foto']); } - $filename = time() . '_' . $request->file('foto')->getClientOriginalName(); - $request->file('foto')->move(public_path('storage/foto_bkk'), $filename); - $data['foto'] = 'foto_bkk/' . $filename; - } else { - unset($data['foto']); - } - $bkk->update($data); - return redirect()->route('bkk.index')->with('success', 'Data BKK berhasil diperbarui.'); -} + $bkk->update($data); + return redirect()->route('bkk.index')->with('success', 'Data BKK berhasil diperbarui.'); + } /** * Remove the specified resource from storage. @@ -121,8 +137,9 @@ public function destroy($id_bkk) $bkk = Bkk::findOrFail($id_bkk); // Hapus foto dari storage jika ada - if ($bkk->foto) { - Storage::disk('public')->delete($bkk->foto); + $storagePath = $this->storagePath(); + if ($bkk->foto && file_exists($storagePath . '/' . $bkk->foto)) { + unlink($storagePath . '/' . $bkk->foto); } $bkk->delete(); diff --git a/app/Http/Controllers/EkstrakurikulerController.php b/app/Http/Controllers/EkstrakurikulerController.php index 19efc38..2323d8e 100644 --- a/app/Http/Controllers/EkstrakurikulerController.php +++ b/app/Http/Controllers/EkstrakurikulerController.php @@ -6,9 +6,15 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; class EkstrakurikulerController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { $data = Ekstrakurikuler::orderBy('id_ekstrakurikuler', 'desc')->paginate(15); @@ -29,11 +35,17 @@ public function store(Request $request) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_ekstrakurikuler', 'public'); + if (!file_exists($storagePath . '/foto_ekstrakurikuler')) { + mkdir($storagePath . '/foto_ekstrakurikuler', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_ekstrakurikuler', $filename); + $data['foto'] = 'foto_ekstrakurikuler/' . $filename; } Ekstrakurikuler::create($data); @@ -58,12 +70,19 @@ public function update(Request $request, $id_ekstrakurikuler) ]); $data = $request->all(); + $storagePath = $this->storagePath(); if ($request->hasFile('foto')) { - if ($ekstrakurikuler->foto && Storage::disk('public')->exists($ekstrakurikuler->foto)) { - Storage::disk('public')->delete($ekstrakurikuler->foto); + if ($ekstrakurikuler->foto && file_exists($storagePath . '/' . $ekstrakurikuler->foto)) { + unlink($storagePath . '/' . $ekstrakurikuler->foto); } - $data['foto'] = $request->file('foto')->store('foto_ekstrakurikuler', 'public'); + + if (!file_exists($storagePath . '/foto_ekstrakurikuler')) { + mkdir($storagePath . '/foto_ekstrakurikuler', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_ekstrakurikuler', $filename); + $data['foto'] = 'foto_ekstrakurikuler/' . $filename; } $ekstrakurikuler->update($data); @@ -74,9 +93,11 @@ public function update(Request $request, $id_ekstrakurikuler) public function destroy($id_ekstrakurikuler) { $ekstrakurikuler = Ekstrakurikuler::findOrFail($id_ekstrakurikuler); + + $storagePath = $this->storagePath(); - if ($ekstrakurikuler->foto && Storage::disk('public')->exists($ekstrakurikuler->foto)) { - Storage::disk('public')->delete($ekstrakurikuler->foto); + if ($ekstrakurikuler->foto && file_exists($storagePath . '/' . $ekstrakurikuler->foto)) { + unlink($storagePath . '/' . $ekstrakurikuler->foto); } $ekstrakurikuler->delete(); diff --git a/app/Http/Controllers/FasilitasController.php b/app/Http/Controllers/FasilitasController.php index f491df8..4c93adb 100644 --- a/app/Http/Controllers/FasilitasController.php +++ b/app/Http/Controllers/FasilitasController.php @@ -5,9 +5,15 @@ use Illuminate\Http\Request; use App\Models\Fasilitas; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; class FasilitasController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { $data = Fasilitas::orderBy('id_fasilitas', 'desc')->paginate(15); @@ -28,12 +34,18 @@ public function store(Request $request) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); // Handle upload foto if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_fasilitas', 'public'); + if (!file_exists($storagePath . '/foto_fasilitas')) { + mkdir($storagePath . '/foto_fasilitas', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_fasilitas', $filename); + $data['foto'] = 'foto_fasilitas/' . $filename; } Fasilitas::create($data); @@ -58,10 +70,21 @@ public function update(Request $request, $id_fasilitas) ]); $data = $request->all(); + $storagePath = $this->storagePath(); // Handle upload foto baru if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_fasilitas', 'public'); + // Hapus foto lama jika ada + if ($fasilitas->foto && file_exists($storagePath . '/' . $fasilitas->foto)) { + unlink($storagePath . '/' . $fasilitas->foto); + } + + if (!file_exists($storagePath . '/foto_fasilitas')) { + mkdir($storagePath . '/foto_fasilitas', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_fasilitas', $filename); + $data['foto'] = 'foto_fasilitas/' . $filename; } else { unset($data['foto']); } @@ -73,7 +96,14 @@ public function update(Request $request, $id_fasilitas) public function destroy($id_fasilitas) { - Fasilitas::findOrFail($id_fasilitas)->delete(); + $fasilitas = Fasilitas::findOrFail($id_fasilitas); + + $storagePath = $this->storagePath(); + if ($fasilitas->foto && file_exists($storagePath . '/' . $fasilitas->foto)) { + unlink($storagePath . '/' . $fasilitas->foto); + } + + $fasilitas->delete(); return redirect()->route('fasilitas.index')->with('success', 'Data berhasil dihapus'); } } diff --git a/app/Http/Controllers/GuruController.php b/app/Http/Controllers/GuruController.php index 5cb8a41..c399dc7 100644 --- a/app/Http/Controllers/GuruController.php +++ b/app/Http/Controllers/GuruController.php @@ -4,9 +4,15 @@ use Illuminate\Http\Request; use App\Models\Guru; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; class GuruController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { $data = Guru::orderBy('id_guru', 'desc')->paginate(15); @@ -31,12 +37,18 @@ public function store(Request $request) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); // Handle upload foto if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_guru', 'public'); + if (!file_exists($storagePath . '/foto_guru')) { + mkdir($storagePath . '/foto_guru', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_guru', $filename); + $data['foto'] = 'foto_guru/' . $filename; } Guru::create($data); @@ -65,10 +77,21 @@ public function update(Request $request, $id_guru) ]); $data = $request->all(); + $storagePath = $this->storagePath(); // Handle upload foto baru if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_guru', 'public'); + // Hapus foto lama jika ada + if ($guru->foto && file_exists($storagePath . '/' . $guru->foto)) { + unlink($storagePath . '/' . $guru->foto); + } + + if (!file_exists($storagePath . '/foto_guru')) { + mkdir($storagePath . '/foto_guru', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_guru', $filename); + $data['foto'] = 'foto_guru/' . $filename; } else { unset($data['foto']); } @@ -80,7 +103,14 @@ public function update(Request $request, $id_guru) public function destroy($id_guru) { - Guru::findOrFail($id_guru)->delete(); + $guru = Guru::findOrFail($id_guru); + + $storagePath = $this->storagePath(); + if ($guru->foto && file_exists($storagePath . '/' . $guru->foto)) { + unlink($storagePath . '/' . $guru->foto); + } + + $guru->delete(); return redirect()->route('guru.index')->with('success', 'Data berhasil dihapus'); } } \ No newline at end of file diff --git a/app/Http/Controllers/InformasiUmumController.php b/app/Http/Controllers/InformasiUmumController.php index c5b5fd4..1aa024d 100644 --- a/app/Http/Controllers/InformasiUmumController.php +++ b/app/Http/Controllers/InformasiUmumController.php @@ -6,9 +6,15 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\File; class InformasiUmumController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { $data = InformasiUmum::orderBy('id_informasi_umum', 'desc')->paginate(15); @@ -30,13 +36,19 @@ public function store(Request $request) ]); $data = $request->all(); + $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); if ($request->hasFile('foto_struktur')) { - $data['foto_struktur'] = $request->file('foto_struktur')->store('foto_informasi_umum', 'public'); + if (!file_exists($storagePath . '/foto_informasi_umum')) { + mkdir($storagePath . '/foto_informasi_umum', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto_struktur')->getClientOriginalName()); + $request->file('foto_struktur')->move($storagePath . '/foto_informasi_umum', $filename); + $data['foto_struktur'] = 'foto_informasi_umum/' . $filename; } - $data['id_user'] = Auth::id(); - InformasiUmum::create($data); return redirect()->route('informasi-umum.index')->with('success', 'Data berhasil ditambahkan'); @@ -60,13 +72,20 @@ public function update(Request $request, $id) ]); $data = $request->all(); + $storagePath = $this->storagePath(); if ($request->hasFile('foto_struktur')) { // Delete old photo if exists - if ($informasiUmum->foto_struktur) { - Storage::disk('public')->delete($informasiUmum->foto_struktur); + if ($informasiUmum->foto_struktur && file_exists($storagePath . '/' . $informasiUmum->foto_struktur)) { + unlink($storagePath . '/' . $informasiUmum->foto_struktur); } - $data['foto_struktur'] = $request->file('foto_struktur')->store('foto_informasi_umum', 'public'); + + if (!file_exists($storagePath . '/foto_informasi_umum')) { + mkdir($storagePath . '/foto_informasi_umum', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto_struktur')->getClientOriginalName()); + $request->file('foto_struktur')->move($storagePath . '/foto_informasi_umum', $filename); + $data['foto_struktur'] = 'foto_informasi_umum/' . $filename; } else { unset($data['foto_struktur']); } @@ -79,9 +98,13 @@ public function update(Request $request, $id) public function destroy($id) { $informasiUmum = InformasiUmum::findOrFail($id); - if ($informasiUmum->foto_struktur) { - Storage::disk('public')->delete($informasiUmum->foto_struktur); + + $storagePath = $this->storagePath(); + + if ($informasiUmum->foto_struktur && file_exists($storagePath . '/' . $informasiUmum->foto_struktur)) { + unlink($storagePath . '/' . $informasiUmum->foto_struktur); } + $informasiUmum->delete(); return redirect()->route('informasi-umum.index')->with('success', 'Data berhasil dihapus'); } diff --git a/app/Http/Controllers/KepalaSekolahController.php b/app/Http/Controllers/KepalaSekolahController.php index 1646b0b..01ad598 100644 --- a/app/Http/Controllers/KepalaSekolahController.php +++ b/app/Http/Controllers/KepalaSekolahController.php @@ -5,10 +5,16 @@ use App\Models\KepalaSekolah; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; use Illuminate\Http\Request; class KepalaSekolahController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { $data = KepalaSekolah::orderBy('id_kepala_sekolah', 'desc')->paginate(15); @@ -33,12 +39,18 @@ public function store(Request $request) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); // Handle upload foto if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_kepala_sekolah', 'public'); + if (!file_exists($storagePath . '/foto_kepala_sekolah')) { + mkdir($storagePath . '/foto_kepala_sekolah', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_kepala_sekolah', $filename); + $data['foto'] = 'foto_kepala_sekolah/' . $filename; } KepalaSekolah::create($data); @@ -66,14 +78,21 @@ public function update(Request $request, $id_kepala_sekolah) ]); $data = $request->all(); + $storagePath = $this->storagePath(); // Handle upload foto baru if ($request->hasFile('foto')) { // Hapus foto lama jika ada - if ($kepala->foto) { - Storage::disk('public')->delete($kepala->foto); + if ($kepala->foto && file_exists($storagePath . '/' . $kepala->foto)) { + unlink($storagePath . '/' . $kepala->foto); } - $data['foto'] = $request->file('foto')->store('foto_kepala_sekolah', 'public'); + + if (!file_exists($storagePath . '/foto_kepala_sekolah')) { + mkdir($storagePath . '/foto_kepala_sekolah', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_kepala_sekolah', $filename); + $data['foto'] = 'foto_kepala_sekolah/' . $filename; } else { unset($data['foto']); } @@ -86,11 +105,14 @@ public function update(Request $request, $id_kepala_sekolah) public function destroy($id_kepala_sekolah) { $kepala = KepalaSekolah::findOrFail($id_kepala_sekolah); + + $storagePath = $this->storagePath(); // Hapus foto dari storage jika ada - if ($kepala->foto) { - Storage::disk('public')->delete($kepala->foto); + if ($kepala->foto && file_exists($storagePath . '/' . $kepala->foto)) { + unlink($storagePath . '/' . $kepala->foto); } + $kepala->delete(); return redirect()->route('kepala-sekolah.index')->with('success', 'Data berhasil dihapus'); } diff --git a/app/Http/Controllers/PbdpController.php b/app/Http/Controllers/PbdpController.php index 52dbd1e..56e90a4 100644 --- a/app/Http/Controllers/PbdpController.php +++ b/app/Http/Controllers/PbdpController.php @@ -6,10 +6,16 @@ use App\Models\Peminat; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; class PbdpController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + public function index() { // gunakan nama variabel $pbdp agar sesuai dengan yang dipakai di Blade @@ -47,11 +53,17 @@ public function store(Request $request) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); if ($request->hasFile('foto')) { - $data['foto'] = $request->file('foto')->store('foto_pbdp', 'public'); + if (!file_exists($storagePath . '/foto_pbdp')) { + mkdir($storagePath . '/foto_pbdp', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_pbdp', $filename); + $data['foto'] = 'foto_pbdp/' . $filename; } Pbdp::create($data); @@ -77,14 +89,21 @@ public function update(Request $request, $id_pbdp) ]); $data = $request->all(); - $data['id_user'] = Auth::id(); + + $storagePath = $this->storagePath(); if ($request->hasFile('foto')) { - if ($pbdp->foto) { - Storage::disk('public')->delete($pbdp->foto); + if ($pbdp->foto && file_exists($storagePath . '/' . $pbdp->foto)) { + unlink($storagePath . '/' . $pbdp->foto); } - $data['foto'] = $request->file('foto')->store('foto_pbdp', 'public'); + + if (!file_exists($storagePath . '/foto_pbdp')) { + mkdir($storagePath . '/foto_pbdp', 0755, true); + } + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $request->file('foto')->getClientOriginalName()); + $request->file('foto')->move($storagePath . '/foto_pbdp', $filename); + $data['foto'] = 'foto_pbdp/' . $filename; } else { unset($data['foto']); } @@ -97,10 +116,13 @@ public function update(Request $request, $id_pbdp) public function destroy($id_pbdp) { $pbdp = Pbdp::findOrFail($id_pbdp); + + $storagePath = $this->storagePath(); - if ($pbdp->foto) { - Storage::disk('public')->delete($pbdp->foto); + if ($pbdp->foto && file_exists($storagePath . '/' . $pbdp->foto)) { + unlink($storagePath . '/' . $pbdp->foto); } + $pbdp->delete(); return redirect()->route('pbdp.index')->with('success', 'Data berhasil dihapus'); } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 8a9b4e0..98bd0bc 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -7,11 +7,17 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\File; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; class ProfileController extends Controller { + protected function storagePath() + { + return env('STORAGE_PATH', public_path('penyimpanan')); + } + /** * Menampilkan halaman form profil. */ @@ -42,11 +48,18 @@ public function update(Request $request) } if ($request->hasFile('foto')) { + $storagePath = $this->storagePath(); + // Hapus foto lama jika ada - if ($user->foto && Storage::disk('public')->exists($user->foto)) { - Storage::disk('public')->delete($user->foto); + if ($user->foto && file_exists($storagePath . '/' . $user->foto)) { + unlink($storagePath . '/' . $user->foto); } - $user->foto = $request->file('foto')->store('profile-photos', 'public'); + + // Simpan foto ke folder penyimpanan eksternal + $file = $request->file('foto'); + $filename = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $file->getClientOriginalName()); + $file->move($storagePath . '/profile-photos', $filename); + $user->foto = 'profile-photos/' . $filename; } $user->save(); diff --git a/config/filesystems.php b/config/filesystems.php index 3d671bd..63e3e86 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -40,8 +40,17 @@ 'public' => [ 'driver' => 'local', - 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'root' => env('STORAGE_PATH', public_path('penyimpanan')), + 'url' => env('STORAGE_URL', '/penyimpanan'), + 'visibility' => 'public', + 'throw' => false, + 'report' => false, + ], + + 'penyimpanan' => [ + 'driver' => 'local', + 'root' => env('STORAGE_PATH', public_path('penyimpanan')), + 'url' => env('STORAGE_URL', '/penyimpanan'), 'visibility' => 'public', 'throw' => false, 'report' => false, @@ -74,7 +83,6 @@ */ 'links' => [ - public_path('storage') => storage_path('app/public'), ], ]; diff --git a/database/migrations/2026_02_11_071058_create_sessions_table.php b/database/migrations/2026_02_11_071058_create_sessions_table.php new file mode 100644 index 0000000..c87eee5 --- /dev/null +++ b/database/migrations/2026_02_11_071058_create_sessions_table.php @@ -0,0 +1,31 @@ +string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->json('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations/2026_02_11_071837_create_cache_table.php b/database/migrations/2026_02_11_071837_create_cache_table.php new file mode 100644 index 0000000..e935016 --- /dev/null +++ b/database/migrations/2026_02_11_071837_create_cache_table.php @@ -0,0 +1,28 @@ +string('key')->primary(); + $table->text('value'); + $table->integer('expiration'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('cache'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 46394d0..3c1164d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,8 +14,8 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // Hapus atau beri komentar user lain jika tidak diperlukan - // dan fokus pada satu user admin yang jelas. + // // Hapus atau beri komentar user lain jika tidak diperlukan + // // dan fokus pada satu user admin yang jelas. User::firstOrCreate( ['email' => 'akunc4086@gmail.com'], [ @@ -48,5 +48,13 @@ public function run(): void ] ); + User::firstOrCreate( + ['email' => 'ardhikayanuar58@gmail.com'], + [ + 'name' => 'Super Admin', + 'password' => Hash::make('password'), + ] + ); + } } diff --git a/resources/views/admin/admin-beranda.blade.php b/resources/views/admin/admin-beranda.blade.php index 2b93685..dffa7ba 100644 --- a/resources/views/admin/admin-beranda.blade.php +++ b/resources/views/admin/admin-beranda.blade.php @@ -47,7 +47,7 @@