1. Go to this page and download the library: Download alfonsobries/laravel-geo 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 AlfonsoBries\Geo\Facades\Geo;
// From a specific IP
$location = Geo::locate('187.190.56.23');
$location->country(); // Country model
$location->division(); // Division model
$location->city(); // City model
$location->timezone; // 'America/Mexico_City'
$location->latitude; // 20.6597
$location->longitude; // -103.3496
// From the current request
$country = Geo::country();
$code = Geo::countryCode(); // 'MX'
use AlfonsoBries\Geo\Models\Continent;
use AlfonsoBries\Geo\Models\Country;
use AlfonsoBries\Geo\Models\Division;
use AlfonsoBries\Geo\Models\City;
// Finders
$mexico = Country::findByCode('MX');
$mexico = Country::findByIso('MEX');
$europe = Continent::findByCode('EU');
$jalisco = Division::findByName('Jalisco');
$gdl = City::findByName('Guadalajara');
// Relationships
$country->continent; // Continent model
$country->divisions; // Collection of Division
$country->cities; // Collection of City
$country->translations; // Collection of CountryTranslation
$country->getTranslation('es'); // "Mexico"
use AlfonsoBries\Geo\Traits\BelongsToCountry;
use AlfonsoBries\Geo\Traits\BelongsToDivision;
use AlfonsoBries\Geo\Traits\BelongsToCity;
use AlfonsoBries\Geo\Traits\BelongsToContinent;
class User extends Model
{
use BelongsToCountry, BelongsToDivision, BelongsToCity;
}