<?php

namespace App\Http\Controllers;

use App\Divisi;
use App\Instansi;
use Illuminate\Http\Request;

class DivisiController extends Controller
{
    public function index()
    {
        $divisis = Divisi::with('instansi')->get();
        return view('divisi.index', compact('divisis'));
    }

    public function create()
    {
        $instansis = Instansi::all();
        return view('divisi.create', compact('instansis'));
    }

    public function store(Request $request)
    {
        $request->validate([
            'nama_divisi' => 'required',
            'instansi_id' => 'required|exists:instansis,id',
        ]);

        Divisi::create($request->all());

        return redirect('/divisi')->with('success','Divisi berhasil ditambahkan');
    }
}
