PHP code example of rahasistiyak / laravel-geo-data
1. Go to this page and download the library: Download rahasistiyak/laravel-geo-data 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/ */
rahasistiyak / laravel-geo-data example snippets
use RahasIstiyak\GeoData\Models\Region;
$regions = Region::all(); // All regions
$dropdown = Region::dropdown(); // ['id', 'name']
$region = Region::byId(1); // By ID
$page = Region::paginate(10, 1); // Paginated results
use RahasIstiyak\GeoData\Models\Country;
$countries = Country::all(); // All countries
$dropdown = Country::dropdown(['id', 'name', 'code']); // Custom fields default if no parameter ['id','name']- if you need more data then send it in parameter
$country = Country::byCode('AF'); // By ISO2/code or ISO3
$country = Country::byId(1); // By ID
$regionCountries = Country::byRegion(3); // By region ID
$page = Country::paginate(10, 1); // Paginated results
use RahasIstiyak\GeoData\Models\PhoneCode;
$phoneCodes = PhoneCode::all(); // All phone codes
$dropdown = PhoneCode::dropdown(); // ['country_id', 'phonecode']
$phoneCode = PhoneCode::byCountryId(1); // By country ID
$page = PhoneCode::paginate(10, 1); // Paginated results
use RahasIstiyak\GeoData\Models\City;
$cities = City::getCities('US'); // All cities in the United States
$dropdown = City::getCityDropdown('US'); // Dropdown ['id', 'name'] for the United States
// If you need more data, send parameters like ['id', 'name', 'latitude']
$dropdownWithAdditionalFields = City::getCityDropdown('US', ['id', 'name', 'latitude']); // Additional fields
$city = City::getCityById('US', 1); // Get city with ID 1 in the United States
use RahasIstiyak\GeoData\Models\Currency;
$currencies = Currency::all(); // All currencies
$dropdown = Currency::dropdown(); // ['country_id', 'currency', 'currency_name']
$currency = Currency::byCountryId(1); // By country ID
$currency = Currency::byCode('AFN'); // By currency code
$page = Currency::paginate(10, 1); // Paginated results
use RahasIstiyak\GeoData\Models\Country;
use RahasIstiyak\GeoData\Models\City;
Route::get('/test-geo', function () {
return response()->json([
'countries' => Country::dropdown(),// you can send parameter for custom fields eg: ['id', 'name', 'code']
'country_af' => Country::byCode('AF'),
'country_1' => Country::byId(1),
'cities_us' => City::getCities('US'), // Cities for the United States
'city_1_us' => City::getCityById('US', 1), // City with ID 1 for US
]);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.