관리-도구
편집 파일: KeywordController.php
<?php namespace App\Http\Controllers; use App\Models\Keyword; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; class KeywordController extends Controller { public function index() { $keyword = Keyword::orderBy('created_at', 'desc')->get(); return view('admin.keyword', compact('keyword')); } public function store(Request $request){ try{ // Validate request data $validateData = $request->validate([ 'keyword' => 'nullable|string', ]); // Create new instance of Counts model $gallery = new Keyword(); $gallery->keyword = $validateData['keyword']; // Save the data $gallery->save(); // Redirect with success message return redirect()->route('admin-keyword.index')->with('success', 'Image added successfully'); } catch(\Exception $e){ // Log error and redirect with error message Log::error('Image uploading error: '. $e->getMessage()); return redirect()->back()->withErrors('Something went wrong during the upload.'); } } public function destroy($id){ $service = Keyword::findOrFail($id); $service->delete(); return redirect()->route('admin-keyword.index')->with('Service deleted successfully'); } public function update(Request $request, $service_id){ try{ // Validate request data $validateData = $request->validate([ 'keyword' => 'required|string', ]); // Find the service by ID $service = Keyword::findOrFail($service_id); // Update title and description $service->keyword = $validateData['keyword']; // Save the updated service $service->save(); // Redirect with success message return redirect()->route('admin-keyword.index')->with('success', 'Service updated successfully.'); } catch(\Exception $e){ // Log the error and redirect with an error message Log::error('Service updating error: '. $e->getMessage()); return redirect()->back()->withErrors('Something went wrong during the update.'); } } }