PHP code example of paulofelipem / brazilian-regions
1. Go to this page and download the library: Download paulofelipem/brazilian-regions 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 PauloFelipeM\BrazilianRegions\Models\Country;
use PauloFelipeM\BrazilianRegions\Models\State;
use PauloFelipeM\BrazilianRegions\Models\City;
// Get all Brazilian states
$brazil = Country::where('acronym', 'BRA')->first();
$states = $brazil->states;
// Get all cities in a state
$state = State::where('acronym', 'SP')->first();
$cities = $state->cities;
// Navigate from city to country
$city = City::where('name', 'São Paulo')->first();
$state = $city->state;
$country = $city->state->country;