You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next run `php artisan vendor:publish --provider="PulkitJalan\GeoIP\GeoIPServiceProvider" --tag="config"` to publish the config file.
45
+
Next run `php artisan vendor:publish --provider="PulkitJalan\IPGeolocation\IPGeolocationServiceProvider" --tag="config"` to publish the config file.
46
46
47
47
#### Using an older version of PHP / Laravel?
48
48
49
49
If you are on a PHP version below 8.1 or a Laravel version below 9.0, use an older version of this package.
50
50
51
51
## Usage
52
52
53
-
The geoip class takes a config array as the first parameter or defaults to using the `ip-api` driver.
53
+
The ipGeolocation class takes a config array as the first parameter or defaults to using the `ip-api` driver.
54
54
55
55
Example:
56
56
57
57
```php
58
58
<?php
59
59
60
-
use PulkitJalan\GeoIP\GeoIP
60
+
use PulkitJalan\IPGeolocation\IPGeolocation
61
61
62
-
$geoip = new GeoIP();
62
+
$ip = new IPGeolocation();
63
63
64
-
$lat = $geoip->getLatitude(); // 51.5141
65
-
$lon = $geoip->getLongitude(); // -3.1969
64
+
$lat = $ip->getLatitude(); // 51.5141
65
+
$lon = $ip->getLongitude(); // -3.1969
66
66
```
67
67
68
68
#### IP-API
@@ -126,137 +126,137 @@ $config = [
126
126
127
127
### Laravel
128
128
129
-
To use this package in Laravel, simply update the config file in `config/geoip.php` to get the same effect. The driver can be set using the `GEOIP_DRIVER` env.
129
+
To use this package in Laravel, simply update the config file in `config/ip-geolocation.php` to get the same effect. The driver can be set using the `IPGEOLOCATION_DRIVER` env.
130
130
131
131
### Available Methods
132
132
133
-
GeoIP will try to determin the ip using the following http headers: `HTTP_CLIENT_IP`, `HTTP_X_FORWARDED_FOR`, `HTTP_X_FORWARDED`, `HTTP_FORWARDED_FOR`, `HTTP_FORWARDED`, `REMOTE_ADDR` in this order. Optionally use the `setIp` method to set it.
133
+
IPGeolocation will try to determin the ip using the following http headers: `HTTP_CLIENT_IP`, `HTTP_X_FORWARDED_FOR`, `HTTP_X_FORWARDED`, `HTTP_FORWARDED_FOR`, `HTTP_FORWARDED`, `REMOTE_ADDR` in this order. Optionally use the `setIp` method to set it.
134
134
135
135
```php
136
-
$geoip->setIp('127.0.0.1');
136
+
$ip->setIp('127.0.0.1');
137
137
138
138
// Laravel
139
-
GeoIP::setIp('127.0.0.1');
139
+
IPGeolocation::setIp('127.0.0.1');
140
140
```
141
141
142
142
There are a number of available methods to pull out the required information. All methods will return an empty string if data is unavailable.
143
143
144
144
Get latitude
145
145
146
146
```php
147
-
$geoip->getLatitude();
147
+
$ip->getLatitude();
148
148
149
149
// Laravel
150
-
GeoIP::getLatitude();
150
+
IPGeolocation::getLatitude();
151
151
```
152
152
153
153
Get longitude
154
154
155
155
```php
156
-
$geoip->getLongitude();
156
+
$ip->getLongitude();
157
157
158
158
// Laravel
159
-
GeoIP::getLongitude();
159
+
IPGeolocation::getLongitude();
160
160
```
161
161
162
162
Get city
163
163
164
164
```php
165
-
$geoip->getCity();
165
+
$ip->getCity();
166
166
167
167
// Laravel
168
-
GeoIP::getCity();
168
+
IPGeolocation::getCity();
169
169
```
170
170
171
171
Get country
172
172
173
173
```php
174
-
$geoip->getCountry();
174
+
$ip->getCountry();
175
175
176
176
// Laravel
177
-
GeoIP::getCountry();
177
+
IPGeolocation::getCountry();
178
178
```
179
179
180
180
Get country code
181
181
182
182
```php
183
-
$geoip->getCountryCode();
183
+
$ip->getCountryCode();
184
184
185
185
// Laravel
186
-
GeoIP::getCountryCode();
186
+
IPGeolocation::getCountryCode();
187
187
```
188
188
189
189
Get region
190
190
191
191
```php
192
-
$geoip->getRegion();
192
+
$ip->getRegion();
193
193
194
194
// Laravel
195
-
GeoIP::getRegion();
195
+
IPGeolocation::getRegion();
196
196
```
197
197
198
198
Get region code
199
199
200
200
```php
201
-
$geoip->getRegionCode();
201
+
$ip->getRegionCode();
202
202
203
203
// Laravel
204
-
GeoIP::getRegionCode();
204
+
IPGeolocation::getRegionCode();
205
205
```
206
206
207
207
Get postal code
208
208
209
209
```php
210
-
$geoip->getPostalCode();
210
+
$ip->getPostalCode();
211
211
212
212
// Laravel
213
-
GeoIP::getPostalCode();
213
+
IPGeolocation::getPostalCode();
214
214
```
215
215
216
216
Get timezone
217
217
218
218
```php
219
-
$geoip->getTimezone();
219
+
$ip->getTimezone();
220
220
221
221
// Laravel
222
-
GeoIP::getTimezone();
222
+
IPGeolocation::getTimezone();
223
223
```
224
224
225
225
Get isp (not supported on all drivers)
226
226
227
227
```php
228
-
$geoip->getIsp();
228
+
$ip->getIsp();
229
229
230
230
// Laravel
231
-
GeoIP::getIsp();
231
+
IPGeolocation::getIsp();
232
232
```
233
233
234
234
Get all geo information
235
235
236
236
```php
237
-
$geoip->get(); // returns array
237
+
$ip->get(); // returns array
238
238
239
239
// Laravel
240
-
GeoIP::get(); // returns array
240
+
IPGeolocation::get(); // returns array
241
241
```
242
242
243
243
Get raw geo information
244
244
245
245
```php
246
-
$geoip->getRaw(); // different drivers will return different data types
246
+
$ip->getRaw(); // different drivers will return different data types
247
247
248
248
// Laravel
249
-
GeoIP::getRaw(); // different drivers will return different data types
249
+
IPGeolocation::getRaw(); // different drivers will return different data types
250
250
```
251
251
252
252
### Update Database
253
253
254
-
There is an update command available to help with updating and installing a local geoip database. The following will download and install/update the database file to `/path/to/database.mmdb`. [As of 30th December 2019, Maxmind requires users to create an account and use a license key to download the databases](https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/).
254
+
There is an update command available to help with updating and installing a local ip geolocation database. The following will download and install/update the database file to `/path/to/database.mmdb`. [As of 30th December 2019, Maxmind requires users to create an account and use a license key to download the databases](https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases/).
255
255
256
256
```php
257
257
<?php
258
258
259
-
use PulkitJalan\GeoIP\GeoIPUpdater
259
+
use PulkitJalan\IPGeolocation\IPGeolocationUpdater
260
260
261
261
$config = [
262
262
'driver' => 'maxmind_database',
@@ -266,12 +266,12 @@ $config = [
266
266
],
267
267
];
268
268
269
-
(new GeoIPUpdater($config))->update();
269
+
(new IPGeolocationUpdater($config))->update();
270
270
```
271
271
272
272
### Laravel
273
273
274
-
Once you have registered the service provider (supports auto discovery), you can use the command `php artisan geoip:update`
274
+
Once you have registered the service provider (supports auto discovery), you can use the command `php artisan ip-geolocation:update`
0 commit comments