<?php

// app/Http/Controllers/ExpenseHeadController.php
namespace App\Http\Controllers;

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

class ExpenseHeadController extends Controller {
    public function index() {
        $heads = ExpenseHead::latest()->paginate(10);
        return view('expenses.heads.index', compact('heads'));
    }

    public function store(Request $request) {
        $request->validate(['name' => 'required|string|max:255']);
        ExpenseHead::create($request->all());
        return back()->with('success', 'Expense Head added successfully.');
    }

    public function destroy(ExpenseHead $expenseHead) {
        $expenseHead->delete();
        return back()->with('success', 'Expense Head deleted successfully.');
    }
}
