Skip to content

Commit 558cfd7

Browse files
committed
#4 Update docs
1 parent c377d9c commit 558cfd7

File tree

2 files changed

+99
-7
lines changed

2 files changed

+99
-7
lines changed

README.md

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,114 @@
66
Determine the geographical location and currency of website visitors based on their IP addresses.
77

88

9+
## About this fork
10+
11+
We have forked [Torann/laravel-geoip](https://github.com/Torann/laravel-geoip) as it’s almost not maintained anymore.
12+
This fork works with modern PHP versions only (8.0+).
13+
Also, as for any InteractionDesignFoundation project, we are going to improving code quality by using types, static analysers, tests and linters.
14+
But don’t worry, we are using SemVer 2.0.
15+
16+
917
## Installation
1018

11-
You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
19+
From the command line run:
1220

13-
```bash
21+
```sh
1422
composer require interaction-design-foundation/laravel-geoip
1523
```
1624

25+
This package also comes with an optional facade, which provides an easy way to call the class.
26+
Open up `config/app.php` and find the aliases key.
27+
28+
```php
29+
'aliases' => [
30+
'GeoIP' => \InteractionDesignFoundation\GeoIP\Facades\GeoIP::class,
31+
];
32+
```
33+
34+
35+
### Publish the configurations
36+
37+
Run this on the command line from the root of your project:
38+
```sh
39+
php artisan vendor:publish --provider="InteractionDesignFoundation\GeoIP\GeoIPServiceProvider" --tag=config
40+
```
41+
42+
43+
## Configuration
44+
45+
Quick breakdown of the two main options in the configuration file.
46+
To find out more simple open the `config/geoip.php` file.
47+
48+
49+
### Service Configuration
50+
51+
To simplify and keep things clean, all third party composer packages, that are needed for a service, are installed separately.
52+
53+
For further configuration options checkout the services page.
1754

18-
## Official Documentation
1955

20-
@todo
56+
### Caching Configuration
2157

58+
GeoIP uses Laravel’s default caching to store queried IP locations.
59+
This is done to reduce the number of calls made to the selected service, as some of them are rate limited.
60+
61+
Options:
62+
- `all` all location are cached
63+
- `some` cache only the requesting user
64+
- `none` caching is completely disable
65+
66+
67+
## Usage
68+
69+
There are few options to use the package:
70+
- `geoip()` helper function
71+
- `InteractionDesignFoundation\GeoIP\Facades\GeoIP` facade
72+
73+
```php
74+
geoip()->getLocation('27.974.399.65'); // Get the location from the provided IP.
75+
geoip()->getClientIP(); // Will return the user IP address.
76+
```
77+
78+
Example of Location object:
79+
```php
80+
\InteractionDesignFoundation\GeoIP\Location {
81+
[
82+
'ip' => '1.1.1.1',
83+
'iso_code' => 'US',
84+
'country' => 'United States',
85+
'city' => 'New Haven',
86+
'state' => 'CT',
87+
'state_name' => 'Connecticut',
88+
'postal_code' => '06510',
89+
'lat' => 41.28,
90+
'lon' => -72.88,
91+
'timezone' => 'America/New_York',
92+
'continent' => 'NA',
93+
'currency' => 'USD',
94+
'default' => false,
95+
]
96+
}
97+
```
98+
99+
`Location` class implements `\ArrayAccess` interface, means you can access properties of the `Location` object using array access syntax:
100+
```php
101+
$location = geoip()->getLocation();
102+
$city = $location['city'];
103+
```
104+
105+
### Artisan
106+
107+
Some services require downloading and use local database to detect Location by IP address.
108+
There is a console command to download/update database:
109+
```sh
110+
php artisan geoip:update
111+
```
112+
113+
Some cache drivers offer the ability to clear cached locations:
114+
```sh
115+
php artisan geoip:clear
116+
```
22117

23118
## Contributions
24119

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
"phpstan": "vendor/bin/phpstan --level=0 --no-progress analyse --configuration phpstan.neon --memory-limit 2G"
5252
},
5353
"extra": {
54-
"branch-alias": {
55-
"dev-master": "1.0-dev"
56-
},
5754
"laravel": {
5855
"providers": [
5956
"InteractionDesignFoundation\\GeoIP\\GeoIPServiceProvider"

0 commit comments

Comments
 (0)