Skip to content

Commit 035e771

Browse files
committed
Update readme
1 parent be6c866 commit 035e771

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,27 @@ Optionally, you can publish the config file of this package with this command:
1919
php artisan vendor:publish --provider="Reefki\Geoip\GeoipServiceProvider" --tag="config"
2020
```
2121

22-
## Usage
22+
## Basic usage
2323
Using facade to get information of an IP address:
2424

2525
```php
2626
use Reefki\Geoip\Geoip;
2727

28-
Geoip::get('8.8.8.8');
29-
Geoip::get('2001:4860:4860:0:0:0:0:8888');
28+
$geoip = Geoip::get('8.8.8.8');
29+
// Or
30+
$geoip = Geoip::get('2001:4860:4860:0:0:0:0:8888');
31+
32+
$geoip->driver; // geojs.
33+
$geoip->ip; // 8.8.8.8
34+
$geoip->city; // Mountain View
35+
$geoip->region; // California
36+
$geoip->country; // United States
37+
$geoip->country_code; // US
38+
$geoip->continent_code; // NA
39+
$geoip->timezone; // America/Chicago
40+
$geoip->latitude; // 37.751
41+
$geoip->longitude; // -97.822
42+
$geoip->cached; // true or false
3043
```
3144

3245
By default the result will be cached, to get realtime data you can pass a boolean value as the second parameter:
@@ -50,6 +63,47 @@ Get visitor's anonymized IP address:
5063
// 2001:4860:4860:0:0:0:0:8888 = 2001:4860:4860::
5164
$anonymizedIp = $request->anonymizedIp();
5265
```
66+
67+
## Drivers
68+
69+
Laravel GeoIP support multiple drivers. By default, `geojs` driver will be used if you don't specify the driver when using the facade or when calling `geoip()` method via Laravel request instance.
70+
71+
You can change the default driver in your `.env` file as:
72+
73+
```
74+
GEOIP_DEFAULT_DRIVER=geojs
75+
```
76+
77+
Here are the drivers currently available for use.
78+
79+
### [GeoJS](https://www.geojs.io)
80+
81+
This is a completly free service, you don't have to do anything to get it to work. Simply pass `geojs` to the driver paremeter.
82+
83+
```php
84+
use Reefki\Geoip\Geoip;
85+
86+
Geoip::driver('geojs')->get('8.8.8.8');
87+
```
88+
89+
### [IPData](https://ipdata.co)
90+
91+
To use this driver, [register](https://dashboard.ipdata.co/sign-up.html) an account and put the API key in your `.env` file as:
92+
93+
```
94+
IPDATA_API_KEY=YOUR_API_KEY
95+
```
96+
97+
To get the IP information using this driver you can pass `ip-data` to the driver parameter:
98+
99+
```php
100+
use Reefki\Geoip\Geoip;
101+
102+
Geoip::driver('ip-data')->get('8.8.8.8');
103+
```
104+
105+
> Please note: IPData offers 1500 daily free requests. If your daily usage is more than 1500 you need to upgrade to one of their paid plan.
106+
53107
## Testing
54108

55109
Run the tests with:

0 commit comments

Comments
 (0)