<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Category;

class CategoryController extends Controller
{
    public function index()
    {
        return view('admin.category.index',[
            'categories' => Category::all()
        ]);
    }
    public function create()
    {
        return view('admin.category.add');
    }
    public function store(Request $request)
    {
        Category::newCategory($request);
        return back()->with('message', 'Category Info Create Successfully');
    }

    public function edit($id)
    {
        return view('admin.category.edit', [
            'category' => Category::find($id)
        ]);
    }
    public function update(Request $request, $id)
    {
        Category::updateCategory($request, $id);
        return redirect('category/manage')->with('message', "Category Info Update Successfully");
    }
    public function delete($id)
    {
        Category::deleteCategory($id);
        return redirect('category/manage')->with('message', "Category Info Deleted Successfully");
    }
}
