Skip to content

Working with Laravel 5

Ruslan A edited this page May 14, 2017 · 2 revisions

Installation

1. Open up config/app.php and add the service provider to providers array:

'providers' => [
    Eseath\SxGeo\SxGeoServiceProvider::class,
]

2. Add the alias to aliases array:

'aliases' => [
    'SxGeo' => Eseath\SxGeo\Facades\SxGeo::class,
]

3. Add a config file to your an appliaction (optionally):

php artisan vendor:publish --provider "Eseath\SxGeo\SxGeoServiceProvider"

Usage

Get full information:

SxGeo::getCityFull($ip)

Get minimal information:

SxGeo::get($ip)

Update the database file:

php artisan sxgeo:update

For updating you need to specify link to database file through dbFileURL parameter in the config:

Default: https://sypexgeo.net/files/SxGeoCity_utf8.zip

Example

<?php
namespace App\Http\Controllers;

use SxGeo;
use Illuminate\Http\Request;

class GeoController
{
    public function index(Request $request)
    {
        $ip = Request::ip();
        $geoData = SxGeo::get($ip);

        return $geoData;
    }
}
Clone this wiki locally