<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Aboutus;
use Illuminate\Http\Request;

class AdminAboutusController extends Controller
{
   public function index()
    {
        $aboutus = Aboutus::first(); // if you only expect one entry
        return view('backoffice.aboutus.index', compact('aboutus'));
    }

    public function store(Request $request)
    {
        $request->validate([
            'title' => 'required|string',
            'banner' => 'required|string',
            'description' => 'nullable|string',
        ]);

        $data = $request->only(['title', 'banner', 'description']);

        $aboutus = Aboutus::first();

        if ($aboutus) {
            $aboutus->update($data);
        } else {
            Aboutus::create($data);
        }

        return redirect()->back()->with('success', 'About Us page saved successfully!');
    }
}
