<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Models\Provinsi;
use App\Http\Models\Kabupaten;
use App\Http\Models\Kecamatan;
use App\Http\Models\Desa;
use Sentinel;

class DashboardController extends Controller
{
    public function home(Request $request)
    {
        $data['mn_active'] = "dashboard";
        return view('dashboard.main', $data);
    }

    // public function getProvinsi(Request $request)
    // {
    //     if(empty($request->id)){
    //         $provinsi = Provinsi::all();
    //     }else{
    //         $provinsi = Provinsi::where('id_provinsi',$request->id)->get();
    //     }

    //     return response()->json($provinsi);
    // }

    public function getKabupaten(Request $request)
    {
        $kabupaten = Kabupaten::where('provinsi_id',$request->id)->get();
        return response()->json($kabupaten);
    }

    public function getKecamatan(Request $request)
    {
        $kecamatan = Kecamatan::where('kabupaten_id',$request->id)->get();
        return response()->json($kecamatan);
    }

    public function getDesa(Request $request)
    {
        $desa = Desa::where('kecamatan_id',$request->id)->get();
        return response()->json($desa);
    }
}
