Skip to content

Commit 6fc010b

Browse files
committed
updated readme and default to ip-api
1 parent 5ec47be commit 6fc010b

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ $config = [
8181
];
8282
```
8383

84+
### Laravel
85+
86+
Just update the config file in `config/packages/pulkitjalan/geoip/config.php` to get the same effect.
87+
8488
### Get Data
8589

8690
Here are the avaliable methods to pull out the required information.
@@ -89,66 +93,99 @@ Set IP (Optional)
8993

9094
```php
9195
$geoip->setIP('127.0.0.1');
96+
97+
// Laravel
98+
GeoIP::setIP('127.0.0.1');
9299
```
93100

94101
Get latitude
95102

96103
```php
97104
$geoip->getLatitude();
105+
106+
// Laravel
107+
GeoIP::getLatitude();
98108
```
99109

100110
Get longitude
101111

102112
```php
103113
$geoip->getLongitude();
114+
115+
//Laravel
116+
GeoIP::getLongitude();
104117
```
105118

106119
Get city
107120

108121
```php
109122
$geoip->getCity();
123+
124+
//Laravel
125+
GeoIP::getCity();
110126
```
111127

112128
Get country
113129

114130
```php
115131
$geoip->getCountry();
132+
133+
//Laravel
134+
GeoIP::getCountry();
116135
```
117136

118137
Get country code
119138

120139
```php
121140
$geoip->getCountryCode();
141+
142+
//Laravel
143+
GeoIP::getCountryCode();
122144
```
123145

124146
Get region
125147

126148
```php
127149
$geoip->getRegion();
150+
151+
//Laravel
152+
GeoIP::getRegion();
128153
```
129154

130155
Get region code
131156

132157
```php
133158
$geoip->getRegionCode();
159+
160+
//Laravel
161+
GeoIP::getRegionCode();
134162
```
135163

136164
Get postal code
137165

138166
```php
139167
$geoip->getPostalCode();
168+
169+
//Laravel
170+
GeoIP::getPostalCode();
140171
```
141172

142173
Get timezone
143174

144175
```php
145176
$geoip->getTimezone();
177+
178+
//Laravel
179+
GeoIP::getTimezone();
146180
```
147181

148182
Get all geo information
149183

150184
```php
151185
$geoip->get(); // returns array
186+
187+
//Laravel
188+
GeoIP::get(); // returns array
152189
```
153190

154191
### Update Database
@@ -171,6 +208,10 @@ $geoipUpdater = new GeoIPUpdater($config);
171208
$geoipUpdater->update();
172209
```
173210

211+
### Laravel
212+
213+
Once you have registered the service provider, you can use the command `php artasin geoip:update`
214+
174215
## Services
175216

176217
### Maxmind

src/GeoIP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GeoIP
2222
/**
2323
* @var array $config
2424
*/
25-
public function __construct(array $config)
25+
public function __construct(array $config = ['driver' => 'ip-api'])
2626
{
2727
$this->driver = with(new GeoIPManager($config))->getDriver();
2828
}

src/GeoIPManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ public function getDriver($driver = null)
3636
throw new InvalidDriverException(sprintf('Driver [%s] does not exist.', $driver));
3737
}
3838

39-
return $this->{$method}();
39+
return $this->{$method}(array_get($this->config, $driver, []));
4040
}
4141

4242
/**
4343
* Get the Maxmind driver
4444
*
4545
* @return \PulkitJalan\GeoIP\MaxmindDriver
4646
*/
47-
protected function createMaxmindDriver()
47+
protected function createMaxmindDriver(array $data)
4848
{
49-
return new MaxmindDriver(array_get($this->config, 'maxmind', []));
49+
return new MaxmindDriver($data);
5050
}
5151

5252
/**
5353
* Get the ip-api driver
5454
*
5555
* @return \PulkitJalan\GeoIP\IPApiDriver
5656
*/
57-
protected function createIpApiDriver()
57+
protected function createIpApiDriver(array $data)
5858
{
59-
return new IPApiDriver([]);
59+
return new IPApiDriver($data);
6060
}
6161
}

src/Laravel/config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Supported: "maxmind", "ip-api"
1010
|
1111
*/
12-
'driver' => 'maxmind',
12+
'driver' => 'ip-api',
1313

1414
/*
1515
|--------------------------------------------------------------------------

tests/GeoIPTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testBadMethodCallException()
2626
{
2727
$this->setExpectedException('BadMethodCallException');
2828

29-
$geoip = new \PulkitJalan\GeoIP\GeoIP(['driver' => 'ip-api']);
29+
$geoip = new \PulkitJalan\GeoIP\GeoIP();
3030

3131
$geoip->setNothing();
3232
}

0 commit comments

Comments
 (0)