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/ */

    

paulofelipem / brazilian-regions example snippets


'providers' => [
    // ...
    PauloFelipeM\BrazilianRegions\BrazilianRegionsServiceProvider::class,
],

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;

return [
    // Override the default Eloquent models
    'models' => [
        'country' => PauloFelipeM\BrazilianRegions\Models\Country::class,
        'state'   => PauloFelipeM\BrazilianRegions\Models\State::class,
        'city'    => PauloFelipeM\BrazilianRegions\Models\City::class,
    ],

    // Customize table names
    'tables' => [
        'countries' => 'countries',
        'states'    => 'states',
        'cities'    => 'cities',
    ],

    // Customize foreign key column names
    'columns' => [
        'country_id' => 'country_id',
        'state_id'   => 'state_id',
        'city_id'    => 'city_id',
    ],
];
bash
php artisan vendor:publish --provider="PauloFelipeM\BrazilianRegions\BrazilianRegionsServiceProvider"
bash
php artisan migrate
php artisan db:seed --class="PauloFelipeM\\BrazilianRegions\\Database\\Seeds\\DatabaseSeeder"