관리-도구
편집 파일: SocialMediaController.php
<?php namespace App\Http\Controllers; use App\Models\SocialMedia; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; class SocialMediaController extends Controller { public function index() { $socials = SocialMedia::orderBy('created_at', 'desc')->get(); return view('admin.socialmedia', compact('socials')); } public function store(Request $request) { try { $data = $request->validate([ 'facebook' => 'nullable|string', 'youtube' => 'nullable|string', 'instagram' => 'nullable|string', 'whatsapp' => 'nullable|string', ]); foreach (['facebook','youtube','instagram','whatsapp'] as $field) { $data[$field . '_status'] = $request->has($field . '_status') ? 'on' : 'off'; } SocialMedia::create($data); return back()->with('success', 'Social media added successfully'); } catch (\Exception $e) { Log::error($e->getMessage()); return back()->with('error', 'Something went wrong'); } } public function update(Request $request, $id) { try { $data = $request->validate([ 'facebook' => 'nullable|string', 'youtube' => 'nullable|string', 'instagram' => 'nullable|string', 'whatsapp' => 'nullable|string', ]); foreach (['facebook','youtube','instagram','whatsapp'] as $field) { $data[$field . '_status'] = $request->has($field . '_status') ? 'on' : 'off'; } $social = SocialMedia::findOrFail($id); $social->update($data); return back()->with('success', 'Social media updated successfully'); } catch (\Exception $e) { Log::error($e->getMessage()); return back()->with('error', 'Unable to update'); } } public function destroy($id) { SocialMedia::findOrFail($id)->delete(); return back()->with('success', 'Deleted successfully'); } }