<?php

namespace App\Http\Controllers\admin;

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

class AdminContactController extends Controller
{
    public function index()
    {
        $contactus = Contact::first();
        return view('backoffice.contact.index', compact('contactus'));
    }

    public function store(Request $request)
    {
        // print_r($request->all());
        // die;

        $request->validate([
            'title' => 'required|string',
            'banner' => 'required|string',
            // 'description' => 'nullable|string',
        ]);

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

        $contact = Contact::first();

        if ($contact) {
            $contact->update($data);
        } else {
            Contact::create($data);
        }
        return redirect()->back()->with('success', 'Contact Us page saved successfully!');
    }
}
