PHP code example of atldays / laravel-geo

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

    

atldays / laravel-geo example snippets


use Atldays\Geo\Facades\Geo;

$country = Geo::country();
$city = Geo::city();
$latitude = Geo::latitude();
$payload = Geo::data();

use Atldays\Geo\Facades\GeoManager;
use Illuminate\Http\Request;

$byIp = GeoManager::ip('8.8.8.8');
$currentRequest = GeoManager::request();

$request = Request::create('/?ip=8.8.8.8', 'GET');
$geo = GeoManager::request($request);

$country = $geo->country();
$city = $geo->city();
$payload = $geo->data();

use Atldays\Geo\Contracts\GeoContract;

class ShowGeoController
{
    public function __invoke(GeoContract $geo)
    {
        return [
            'ip' => $geo->ip(),
            'country' => $geo->country()?->getIsoCode(),
            'city' => $geo->city()?->getName(),
        ];
    }
}

use Atldays\Geo\Drivers\IpApi;

return [
    'driver' => IpApi::class,
    'fallbacks' => [],
];

use Atldays\Geo\Drivers\IpApi;
use Atldays\Geo\Drivers\MaxMind;

return [
    'driver' => MaxMind::class,
    'fallbacks' => [
        IpApi::class,
    ],
];

'request' => [
    'fake_ip_key' => env('GEO_FAKE_IP_KEY', 'ip'),
],

// In debug mode, with GEO_FAKE_IP_KEY=ip
// GET /some-page?ip=8.8.8.8

Geo::country();

use Illuminate\Http\Request;

$request = Request::create('/?ip=8.8.8.8', 'GET');
$geo = $request->geo();

$country = $geo->country();
$city = $geo->city();

use Atldays\Geo\Facades\Geo;
use Atldays\Geo\Facades\GeoManager;

$currentCountry = Geo::country();
$byIp = GeoManager::ip('8.8.8.8');

'ip_api' => [
    'base_url' => env('GEO_IP_API_BASE_URL', 'http://ip-api.com'),
    'timeout' => env('GEO_IP_API_TIMEOUT'),
],

'maxmind' => [
    'account_id' => env('MAXMIND_ACCOUNT_ID'),
    'license_key' => env('MAXMIND_LICENSE_KEY'),
    'edition_id' => env('MAXMIND_EDITION_ID', 'GeoLite2-City'),
    'download_url' => env('MAXMIND_DOWNLOAD_URL'),
    'database_path' => env('MAXMIND_DATABASE_PATH', storage_path('app/geo/maxmind')),
    'database_filename' => env('MAXMIND_DATABASE_FILENAME'),
    'metadata_filename' => env('MAXMIND_METADATA_FILENAME', 'metadata.json'),
],

'definitions' => [
    'country' => \Atldays\Geo\CountryDefinitions\Rinvex::class,
],

$definition = Geo::country()?->definition();

$officialName = $definition?->getOfficialName();
$currencies = $definition?->getCurrencies();
$translations = $definition?->getTranslations();
bash
php artisan vendor:publish --tag=laravel-geo-config
bash
php artisan geo:update
bash
php artisan geo:update --force