PHP code example of gerardojbaez / geodata

1. Go to this page and download the library: Download gerardojbaez/geodata 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/ */

    

gerardojbaez / geodata example snippets




'providers' => [

	[...]

	/**
	 * Third Party Service Providers...
	 */
	Gerardojbaez\GeoData\GeoDataServiceProvider::class,
]



namespace App\Models;

// [...]
use Gerardojbaez\GeoData\Contracts\HasCountryContract;
use Gerardojbaez\GeoData\Contracts\HasRegionContract;
use Gerardojbaez\GeoData\Contracts\HasCityContract;
use Gerardojbaez\GeoData\Traits\HasCountry;
use Gerardojbaez\GeoData\Traits\HasRegion;
use Gerardojbaez\GeoData\Traits\HasCity;

class User extends Model implements HasCountryContract, HasRegionContract, HasCityContract
{
	use HasCountry, HasRegion, HasCity;

	/**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'country_code',
        'region_id',
        'city_id',
        ...
    ];



use Gerardojbaez\Geodata\CountryInstaller;

// Install United States.
$installer = new CountryInstaller('United States');
$installer->install();

// Install Puerto Rico.
$installer = new CountryInstaller('Puerto Rico');
$installer->install();

// Install Spain
$installer = new CountryInstaller('Spain');
$installer->install();



// Show countries list.
Route::get('api/geo/countries', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\CountriesController@countries',
	'as' => 'geodata.countries'
]);

// Show regions list.
Route::get('api/geo/{country}/regions', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\RegionsController@regions',
	'as' => 'geodata.regions'
]);

// Show cities list.
Route::get('api/geo/{country}/{region}/cities', [
	'uses' => '\Gerardojbaez\GeoData\Controllers\CitiesController@cities',
	'as' => 'geodata.cities'
]);
js
{
    ""php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "gerardojbaez/geodata": "0.*"
    }
}