<?php

namespace App\Http\Controllers;

use App\Models\SubUnit;
use App\Models\Unit;
use Illuminate\Http\Request;

class SubUnitController extends Controller
{
    public function index()
    {
        $data['subunit'] = SubUnit::with('unit')->get();
        $data['unit'] = Unit::all();

        return view('pages.master.subunit', $data);
    }

    public function add(Request $request)
    {
        SubUnit::create($request->all());

        return redirect()->back()->with('success', 'Data Berhasil Disimpan');
    }

    public function update(Request $request, $id)
    {
        SubUnit::find($id)->update($request->all());

        return redirect()->back()->with('success', 'Data Berhasil Disimpan');
    }

    public function delete($id)
    {
        SubUnit::find($id)->delete();

        return redirect()->back()->with('success', 'Data Berhasil Dihapus');
    }
}
