true, 'showMenu' => true ]; $breadcrumbs = [['link' => '/admin/category/' . $category->id . '/edit', 'name' => 'Notes'], ['name' => 'Add']]; return view('content.categories.notes.create', [ 'pageConfigs' => $pageConfigs, 'breadcrumbs' => $breadcrumbs, 'category' => $category ]); } public function store(Request $request) { $request->validate([ 'category_id' => ['required'], 'title' => ['required'], 'pdf' => ['required'], ]); try { DB::beginTransaction(); $notes = new CategoryNotes(); $notes->category_id = $request->category_id; $notes->title = $request->title; if ($request->hasFile('pdf')) { $pdfPath = $this->uploadPDF($request->pdf, 'pdf'); $notes->pdf = $pdfPath; } $notes->save(); DB::commit(); return redirect()->route('category.edit', $request->category_id)->with([ 'success' => "Notes created successfully" ]); } catch (\Throwable $exception) { DB::rollBack(); return redirect()->back()->with([ 'error' => $exception->getMessage() ]); } } public function downloadPDF(CategoryNotes $notes) { $path = public_path('storage'.$notes->pdf); return response()->download($path); } public function edit(CategoryNotes $notes) { $pageConfigs = [ 'pageHeader' => true, 'showMenu' => true ]; $breadcrumbs = [['link' => '/admin/category/' . $notes->category_id . '/edit', 'name' => 'Notes'], ['name' => 'Edit']]; // $breadcrumbs = [['link' => '/admin/category', 'name' => 'Course'], ['name' => 'Edit']]; return view('content.categories.notes.edit', [ 'pageConfigs' => $pageConfigs, 'breadcrumbs' => $breadcrumbs, 'note' => $notes, ]); } public function update(Request $request, CategoryNotes $notes) { $request->validate([ 'title' => ['required'], 'pdf' => ['nullable'], ]); try { DB::beginTransaction(); $notes->title = $request->title; if ($request->hasFile('pdf')) { $this->deleteFile($notes->pdf); $pdfPath = $this->uploadPDF($request->pdf, 'pdf'); $notes->pdf = $pdfPath; } $notes->update(); DB::commit(); return redirect()->route('category.edit', $notes->category_id)->with([ 'success' => "Notes updated successfully" ]); } catch (\Throwable $exception) { DB::rollBack(); return redirect()->back()->with([ 'error' => $exception->getMessage() ]); } } public function destroy(CategoryNotes $notes) { try { DB::beginTransaction(); $this->deleteFile($notes->pdf); $notes->delete(); DB::commit(); return redirect()->back()->with([ 'success' => "Notes deleted successfully" ]); } catch (\Throwable $exception) { DB::rollBack(); return redirect()->back()->with([ 'error' => $exception->getMessage() ]); } } }