<?php

namespace App\Http\Controllers;

use App\Models\District;
use App\Models\Province;
use App\Models\Regency;
use Dflydev\DotAccessData\Data;
use Illuminate\Http\Request;

class LocationController extends Controller
{
    public function getProvinces()
    {
        $provinces = Province::all();
        return response()->json(['success' => true, 'data' => $provinces]);
    }

    public function getRegencies($provinceId)
    {
        $regencies = Regency::where('province_id', $provinceId)->get();
        return response()->json(['success' => true, 'data' => $regencies]);
    }

    public function getDistricts($regencyId)
    {
        $distircts = District::where('regency_id', $regencyId)->get();
        return response()->json(['success' => true, 'data' => $distircts]);
    }
}
