There are few options to use the package:
geoip()
helper functionInteractionDesignFoundation\GeoIP\Facades\GeoIP
facadegeoip()->getLocation('27.974.399.65'); // Get the location from the provided IP.
geoip()->getClientIP(); // Will return the user IP address.
Example of a Location object:
\InteractionDesignFoundation\GeoIP\Location {[
'ip' => '1.1.1.1',
'iso_code' => 'US',
'country' => 'United States',
'city' => 'New Haven',
'state' => 'CT',
'state_name' => 'Connecticut',
'postal_code' => '06510',
'lat' => 41.28,
'lon' => -72.88,
'timezone' => 'America/New_York',
'continent' => 'NA',
'currency' => 'USD',
'default' => false,
]}
Location
class implements \ArrayAccess
interface, means you can access properties of the Location
object using both object and array access:
$location = geoip()->getLocation();
$city = $location->city;
// The same as:
$city = $location['city'];