diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index c7facf0..c37cd6e 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -43,6 +43,36 @@ class AjaxController extends Controller 'message' => 'Upload failed.', ]); } + public function uploadTempImage(Request $request) + { + $request->validate([ + 'file.*' => 'required|file|mimes:png,jpg,jpeg|max:5120', + ]); + + $uploadedFiles = []; + + if ($request->hasFile('file')) { + foreach ($request->file('file') as $file) { + $filename = uniqid() . '-' . time() . '.' . $file->getClientOriginalExtension(); + $path = $file->storeAs('tmp_uploads', $filename); + + $uploadedFiles[] = [ + 'filename' => $filename, + 'url' => asset('storage/tmp_uploads/' . $filename), + ]; + } + + return response()->json([ + 'success' => true, + 'files' => $uploadedFiles, // Kembalikan semua file + ]); + } + + return response()->json([ + 'success' => false, + 'message' => 'Upload failed.', + ]); + } public function sekolahNpsn(Request $request) { // dd($request->all()); diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 6972483..f9b7e07 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -23,6 +23,7 @@ class FrontController extends Controller return view('kegiatan_detail',$data); } function galeri() { - return view('galeri'); + $data['kegiatan'] = Kegiatan::orderBy('KegiatanId','DESC')->paginate(8); + return view('galeri',$data); } } diff --git a/app/Http/Controllers/Modules/Konten/KegiatanController.php b/app/Http/Controllers/Modules/Konten/KegiatanController.php index 3499b6f..c5033bd 100644 --- a/app/Http/Controllers/Modules/Konten/KegiatanController.php +++ b/app/Http/Controllers/Modules/Konten/KegiatanController.php @@ -45,13 +45,14 @@ class KegiatanController extends Controller $action .= ''; $action .= ''; } + $image = json_decode($row->image); $_data[] = [ 'no' => $key+1, 'id' => encode_id($row->KegiatanId), 'judul' => $row->judul, 'created_at' => dateTime($row->created_at), - 'image' => '', + 'image' => '', 'action' => $action, ]; @@ -93,30 +94,46 @@ class KegiatanController extends Controller $keg->kategori = $request->kategori; $keg->body = $request->body; - if (@$request->hasFile('image')) { - $file = $request->file('image'); - $destinationPath = public_path('uploads/kegiatan'); - $current = Carbon::now()->format('Y/m/d'); - $path = $destinationPath . '/' . $current; - $fileName = $file->getClientOriginalName(); - $fileMime = $file->getClientMimeType(); - $fileExtension = $file->getClientOriginalExtension(); - $fileSize = $file->getSize(); - if(($fileExtension != 'jpg') && ($fileExtension != 'jpeg') && ($fileExtension != 'png')){ - return redirect()->back()->with([ - 'message' => 'Maaf File Harus Berupa PNG,JPEG,JPG!', - 'type' => "error" - ]); - } - $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; + if(@$request->input_upload_files){ - if (!File::exists($path)) { - File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); - } + $filePaths = []; + if(is_array(@$request->input_upload_files)){ - $filePathTim = 'kegiatan/' . $current . '/' . $newFilename; - $uploaded = $file->move($path, $newFilename); - $keg->image = $filePathTim; + $oldImages = json_decode($keg->image, true) ?? []; + foreach (@$request->input_upload_files as $file) { + $tempPath = storage_path('app/tmp_uploads/' . $file); + + if (file_exists($tempPath)) { + $path = public_path('uploads/kegiatan/' . date('Y') ); + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $newPath = 'uploads/kegiatan/'.date('Y').'/'.$file; + copy($tempPath, public_path($newPath)); + $newfilePaths[] = $newPath; + } + } + + // gabungkan file lama + file baru + $filePaths = array_merge($oldImages, $newfilePaths); + }else{ + $tempPath = storage_path('app/tmp_uploads/' . @$request->input_upload_files); + + if (file_exists($tempPath)) { + $path = public_path('uploads/kegiatan/' . date('Y') ); + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $newPath = 'uploads/kegiatan/'.date('Y').'/'.@$request->input_upload_files; + copy($tempPath, public_path($newPath)); + $filePaths[] = $newPath; + } + } + + $path = $filePaths; + $keg->image = json_encode($path); } $keg->save(); }else{ @@ -126,31 +143,69 @@ class KegiatanController extends Controller $keg->kategori = $request->kategori; $keg->body = $request->body; - if (@$request->hasFile('image')) { - $file = $request->file('image'); - $destinationPath = public_path('uploads/kegiatan'); - $current = Carbon::now()->format('Y/m/d'); - $path = $destinationPath . '/' . $current; - $fileName = $file->getClientOriginalName(); - $fileMime = $file->getClientMimeType(); - $fileExtension = $file->getClientOriginalExtension(); - $fileSize = $file->getSize(); - if(($fileExtension != 'jpg') && ($fileExtension != 'jpeg') && ($fileExtension != 'png')){ - return redirect()->back()->with([ - 'message' => 'Maaf File Harus Berupa PNG,JPEG,JPG!', - 'type' => "error" - ]); - } - $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; + // if (@$request->hasFile('image')) { + // $file = $request->file('image'); + // $destinationPath = public_path('uploads/kegiatan'); + // $current = Carbon::now()->format('Y/m/d'); + // $path = $destinationPath . '/' . $current; + // $fileName = $file->getClientOriginalName(); + // $fileMime = $file->getClientMimeType(); + // $fileExtension = $file->getClientOriginalExtension(); + // $fileSize = $file->getSize(); + // if(($fileExtension != 'jpg') && ($fileExtension != 'jpeg') && ($fileExtension != 'png')){ + // return redirect()->back()->with([ + // 'message' => 'Maaf File Harus Berupa PNG,JPEG,JPG!', + // 'type' => "error" + // ]); + // } + // $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; - if (!File::exists($path)) { - File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); - } + // if (!File::exists($path)) { + // File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + // } - $filePathTim = 'kegiatan/' . $current . '/' . $newFilename; - $uploaded = $file->move($path, $newFilename); - $keg->image = $filePathTim; + // $filePathTim = 'kegiatan/' . $current . '/' . $newFilename; + // $uploaded = $file->move($path, $newFilename); + // $keg->image = $filePathTim; + // } + + if(@$request->input_upload_files){ + + $filePaths = []; + if(is_array(@$request->input_upload_files)){ + foreach (@$request->input_upload_files as $file) { + $tempPath = storage_path('app/tmp_uploads/' . $file); + + if (file_exists($tempPath)) { + $path = public_path('uploads/kegiatan/' . date('Y') ); + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $newPath = 'uploads/kegiatan/'.date('Y').'/'.$file; + copy($tempPath, public_path($newPath)); + $filePaths[] = $newPath; + } + } + }else{ + $tempPath = storage_path('app/tmp_uploads/' . @$request->input_upload_files); + + if (file_exists($tempPath)) { + $path = public_path('uploads/kegiatan/' . date('Y') ); + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $newPath = 'uploads/kegiatan/'.date('Y').'/'.@$request->input_upload_files; + copy($tempPath, public_path($newPath)); + $filePaths[] = $newPath; + } + } + + $path = $filePaths; + $keg->image = json_encode($path); } + $keg->save(); } return redirect()->back()->with([ @@ -224,4 +279,34 @@ class KegiatanController extends Controller return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']); } + function imageDelete(Request $request,$id){ + $keyId = decode_id($id); + $keg = Kegiatan::where('KegiatanId',$keyId)->first(); + + // Ambil nama file yang mau dihapus + $fileToDelete = $request->url; // contoh: 'uploads/kegiatan/2025/file2.pdf' + + // Ambil data lama + $images = json_decode($keg->image, true) ?? []; + + // Cari dan hapus dari array + $newImages = array_filter($images, function ($img) use ($fileToDelete) { + return $img !== $fileToDelete; + }); + + // Hapus file fisik juga + $fullPath = public_path($fileToDelete); + if (File::exists($fullPath)) { + File::delete($fullPath); + } + + // Simpan array baru ke DB + $keg->image = json_encode(array_values($newImages)); // reset index array + $keg->save(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Image deleted successfully', + ]); + } } diff --git a/database/migrations/2025_08_08_085907_create_kegiatans_table.php b/database/migrations/2025_08_08_085907_create_kegiatans_table.php index 7dc47b7..5d67497 100644 --- a/database/migrations/2025_08_08_085907_create_kegiatans_table.php +++ b/database/migrations/2025_08_08_085907_create_kegiatans_table.php @@ -17,7 +17,7 @@ return new class extends Migration $table->string('judul')->nullable(); $table->text('body')->nullable(); $table->string('kategori')->nullable(); - $table->string('image')->nullable(); + $table->json('image')->nullable(); $table->timestampsTz(); }); } diff --git a/resources/views/galeri.blade.php b/resources/views/galeri.blade.php index ef6efdb..035779d 100644 --- a/resources/views/galeri.blade.php +++ b/resources/views/galeri.blade.php @@ -6,98 +6,36 @@ + @foreach($kegiatan as $dataKeg) + image); + ?> - + - Dokumentasi SDN 15 Ciracas + {{ $dataKeg->judul }} {{-- 1 Agustus 2025 --}} {{-- Open dialog --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 05 Pondok Kelapa - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMAN 67 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi MAN 2 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 04 Lebak Bulus - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMAN 10 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 07 Pulogadung - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMPN 197 Jakarta - {{-- 1 Agustus 2025 --}} - + Lihat Detail + @endforeach - - - - + + + + ‹ + › + + Tutup @@ -106,12 +44,44 @@ @section('js') @endsection \ No newline at end of file diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 378c698..7c6bb7e 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -88,7 +88,10 @@ - + image); + ?> + Kegiatan {{ $kegiatan[0]->kategori }} {{ date('D',strtotime($kegiatan[0]->created_at)) }}, {{ date('d M Y',strtotime($kegiatan[0]->created_at)) }} @@ -105,9 +108,12 @@ @foreach($kegiatan as $dataKeg) + image); + ?> - + {{ date('D',strtotime($dataKeg->created_at)) }}, {{ date('d M Y',strtotime($dataKeg->created_at)) }} @@ -130,87 +136,80 @@ + @foreach($kegiatan as $dataKeg) + image); + ?> - + - Dokumentasi SDN 15 Ciracas + {{ $dataKeg->judul }} {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 05 Pondok Kelapa - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMAN 67 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi MAN 2 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 04 Lebak Bulus - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMAN 10 Jakarta - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SDN 07 Pulogadung - {{-- 1 Agustus 2025 --}} - - Lihat Detail - - - - - - - Dokumentasi SMPN 197 Jakarta - {{-- 1 Agustus 2025 --}} - + Lihat Detail + @endforeach + + + + + + + ‹ + › + + + Tutup + + + +@endsection +@section('js') + + @endsection \ No newline at end of file diff --git a/resources/views/kegiatan.blade.php b/resources/views/kegiatan.blade.php index 6d0c008..f4bae9e 100644 --- a/resources/views/kegiatan.blade.php +++ b/resources/views/kegiatan.blade.php @@ -7,9 +7,12 @@ @foreach($kegiatan as $dataKeg) + image); + ?> - + Kegiatan {{ $dataKeg->kategori }} {{ date('D',strtotime($dataKeg->created_at)) }}, {{ date('d M Y',strtotime($dataKeg->created_at)) }} diff --git a/resources/views/kegiatan_detail.blade.php b/resources/views/kegiatan_detail.blade.php index 9fc60f3..8433e27 100644 --- a/resources/views/kegiatan_detail.blade.php +++ b/resources/views/kegiatan_detail.blade.php @@ -5,7 +5,44 @@ - + + image); + ?> + + + + + @foreach ($image as $img) + + + + @endforeach + + + + + + ‹ + + + + + › + + + + + @foreach ($image as $index => $img) + + @endforeach + + + + + {{-- --}} Kegiatan {{ $kegiatan->kategori }} {{ date('D',strtotime($kegiatan->created_at)) }}, {{ date('d M Y',strtotime($kegiatan->created_at)) }} @@ -46,9 +83,12 @@ @foreach($lainnya as $dataKeg) + image); + ?> - + {{ date('D',strtotime($dataKeg->created_at)) }}, {{ date('d M Y',strtotime($dataKeg->created_at)) }} @@ -89,4 +129,40 @@ window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${url}`, '_blank', 'noopener,noreferrer,width=600,height=400'); } + + @endsection \ No newline at end of file diff --git a/resources/views/modules/konten/kegiatan/form.blade.php b/resources/views/modules/konten/kegiatan/form.blade.php index fefd89f..b8d0f24 100644 --- a/resources/views/modules/konten/kegiatan/form.blade.php +++ b/resources/views/modules/konten/kegiatan/form.blade.php @@ -1,6 +1,7 @@ @extends('layouts.master') @section('page-css') + @endsection @section('breadcrumbs') @@ -22,7 +23,7 @@ {{$title}} - + {{csrf_field()}} @@ -76,7 +77,16 @@ Image - + {{-- --}} + + + Drop PDF files here or click to upload + + + + + + @error('image') {{$message}} @enderror @@ -84,6 +94,26 @@ + @if(@$item->image) + image); + ?> + + + + + @foreach($image as $img) + + + Hapus + + @endforeach + + + + + @endif +
1 Agustus 2025