1. Go to this page and download the library: Download zmap95/vietnam-maps library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Zmap95\VietnamMap\Models\Province;
use Zmap95\VietnamMap\Models\District;
use Zmap95\VietnamMap\Models\Ward;
class DevController extends Controller
{
...
public function dev()
{
$provinces = Province::all();
$districts = District::all();
$wards = Ward::all();
...
}
}
use zmap95\VietnamMap\Models\Province;
class DevController extends Controller
{
...
public function dev()
{
$province = Province::first();
$districts = $province->districts;
...
}
}
class Province extends Model
{
...
public function districts()
{
return $this->hasMany(District::class);
}
}
class District extends Model
{
...
public function province()
{
return $this->belongsTo(Province::class, config('vietnam-maps.columns.province_id'), 'id');
}
public function wards()
{
return $this->hasMany(Ward::class);
}
}
class Ward extends Model
{
...
public function district()
{
return $this->belongsTo(District::class, config('vietnam-maps.columns.district_id'), 'id');
}
}