HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/orbidirectory.com/app/Http/Controllers/SeoController.php
<?php

namespace App\Http\Controllers;

use App\Models\Seo;
use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;

class SeoController extends Controller
{
    /**
     * Display the SEO index view.
     */
    public function index()
    {
        return view('admin.seo.index');
    }

    /**
     * Show the form for creating a new SEO record.
     */
    public function create()
    {
        return view('admin.seo.create');
    }

    /**
     * Store a newly created SEO record in storage.
     */
    public function store(Request $request)
    {
        try {
            // Validate the request data for all fields
            $validated = $request->validate([
                'route_name' => 'required|string|max:255',
                'meta_title' => 'required|string|max:255',
                'meta_keywords' => 'required|string|max:255',
                'meta_description' => 'required|string',
                'canonical_tag' => 'nullable|url',
                'og_title' => 'nullable|string|max:255',
                'og_description' => 'nullable|string',
                'og_image' => 'nullable|url',
                'og_url' => 'nullable|url',
                'twitter_card' => 'nullable|string|max:255',
                'twitter_title' => 'nullable|string|max:255',
                'twitter_description' => 'nullable|string',
                'twitter_image' => 'nullable|url',
            ]);

            // Create the SEO record with all validated fields
            Seo::create($validated);

            return redirect()->route('seo.index')->with('success', 'SEO is created successfully.');
        } catch (\Exception $e) {
            report($e);
            return redirect()->back()->withInput()->with('error', 'Something went wrong: ' . $e->getMessage());
        }
    }

    /**
     * Show the form for editing the specified SEO record.
     */
    public function edit($id)
    {
        $seo = Seo::findOrFail($id);
        return view('admin.seo.edit', compact('seo'));
    }

    /**
     * Update the specified SEO record in storage.
     */
    public function update(Request $request, $id)
    {
        try {
            // Validate the request data for all fields
            $validated = $request->validate([
                'route_name' => 'required|string|max:255',
                'meta_title' => 'required|string|max:255',
                'meta_keywords' => 'required|string|max:255',
                'meta_description' => 'required|string',
                'canonical_tag' => 'nullable|url',
                'og_title' => 'nullable|string|max:255',
                'og_description' => 'nullable|string',
                'og_image' => 'nullable|url',
                'og_url' => 'nullable|url',
                'twitter_card' => 'nullable|string|max:255',
                'twitter_title' => 'nullable|string|max:255',
                'twitter_description' => 'nullable|string',
                'twitter_image' => 'nullable|url',
            ]);

            // Find the SEO record and update it with validated data
            $seo = Seo::findOrFail($id);
            $seo->update($validated);

            return redirect()->route('seo.index')->with('success', 'SEO updated successfully.');
        } catch (\Exception $e) {
            report($e);
            return redirect()->back()->withInput()->with('error', 'Something went wrong: ' . $e->getMessage());
        }
    }

    /**
     * Remove the specified SEO record from storage.
     */
    public function destroy($id)
    {
        try {
            $seo = Seo::findOrFail($id);
            $seo->delete();

            return redirect()->route('seo.index')->with('success', 'SEO record deleted successfully.');
        } catch (\Exception $e) {
            return redirect()->route('seo.index')->with('error', 'Something went wrong: ' . $e->getMessage());
        }
    }

    /**
     * Get the list of SEO records for DataTables.
     */
    public function list()
    {
        try {
            $seo = Seo::orderBy('created_at', 'ASC');
            $datatable = DataTables::eloquent($seo)
                ->addColumn("action", function ($row) {
                    return view('admin.seo.action', compact('row'));
                })
                ->rawColumns(['action'])
                ->make(true);
            return $datatable;
        } catch (\Exception $e) {
            return response()->json(['error' => $e->getMessage()], 500);
        }
    }
}