'Rekap Konten', 'classification' => $request->input('classification', null) ]); } public function create(){ return view('dashboard.content-recaps.create', [ 'title' => 'Tambah Rekap Konten', 'classifications' => ContentRecapClassification::all() ]); } public function store(ContentRecapRequest $request){ $validatedData = $request->validated(); $validatedData['enhancer_id'] = Auth::id(); if($request->has('image') && filled($validatedData['image'])){ $validatedData['image'] = store_file($validatedData['image'], '/uploads/content-recaps', 'public')['randomFileName']; }else{ $validatedData['image'] = null; } try{ $createdContentRecap = ContentRecap::create($validatedData); return redirect()->route('dashboard.content.recaps.index')->with('success-status', 'Berhasil menambahkan rekap konten.') ->with('new_data', encrypt_id($createdContentRecap->id)); }catch(\Exception $e){ return redirect()->back()->with('failed-status', 'Gagal menambahkan rekap konten.'); } } public function edit($id){ $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); return view('dashboard.content-recaps.edit', [ 'title' => 'Ubah Rekap Konten', 'contentRecap' => $contentRecap, 'classifications' => ContentRecapClassification::all() ]); } public function update(ContentRecapRequest $request, $id){ $validatedData = $request->validated(); $validatedData['enhancer_id'] = Auth::id(); $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); if($request->has('image') && filled($validatedData['image'])){ delete_file('app/public/uploads/content-recaps/'.$contentRecap->image); $validatedData['image'] = store_file($validatedData['image'], '/uploads/content-recaps', 'public')['randomFileName']; }else{ $validatedData['image'] = $contentRecap->image; } try{ $contentRecap->update($validatedData); return redirect()->route('dashboard.content.recaps.show', ['id' => encrypt_id($contentRecap->id)])->with('success-status', 'Berhasil mengubah rekap konten.'); }catch(\Exception $e){ return redirect()->back()->with('failed-status', 'Gagal mengubah rekap konten.'); } } public function show($id){ $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); return view('dashboard.content-recaps.show', [ 'title' => 'Detail Rekap Konten', 'contentRecap' => $contentRecap ]); } public function destroy($id){ try { $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); $contentRecap->delete(); return response()->json(['message' => 'Berhasil menghapus rekap konten.']); } catch (\Exception $e) { return response()->json(['message' => 'Gagal menghapus rekap konten.'], 500); } } public function checkLink(Request $request) { $linkExists = ContentRecap::where('link', $request->link)->exists(); return response()->json([ 'exists' => $linkExists ]); } }