<?php

namespace App\Http\Controllers\Admin;

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

class MailroomHeroController extends Controller
{
    function __construct()
    {
        $this->middleware('role_or_permission:mailroom hero section', ['only' => ['index', 'update']]);
    }

    function index()
    {
        $data = MailroomHero::first();
        return view('admin.mailroom.hero.index', compact('data'));
    }

    function update(Request $request)
    {
        $request->validate([
            'title' => ['required'],
            'description' => ['required']
        ]);

        MailroomHero::query()->UpdateOrCreate([
            'id' => 1
        ], [
            'title' => $request->title,
            'description' => $request->description
        ]);

        $notification = array(
            'messege' => 'Updated successfully',
            'alert-type' => 'success'
        );
        return back()->with($notification);
    }
}
