File tree Expand file tree Collapse file tree 5 files changed +49
-8
lines changed Expand file tree Collapse file tree 5 files changed +49
-8
lines changed Original file line number Diff line number Diff 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
8690Here 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
94101Get latitude
95102
96103``` php
97104$geoip->getLatitude();
105+
106+ // Laravel
107+ GeoIP::getLatitude();
98108```
99109
100110Get longitude
101111
102112``` php
103113$geoip->getLongitude();
114+
115+ //Laravel
116+ GeoIP::getLongitude();
104117```
105118
106119Get city
107120
108121``` php
109122$geoip->getCity();
123+
124+ //Laravel
125+ GeoIP::getCity();
110126```
111127
112128Get country
113129
114130``` php
115131$geoip->getCountry();
132+
133+ //Laravel
134+ GeoIP::getCountry();
116135```
117136
118137Get country code
119138
120139``` php
121140$geoip->getCountryCode();
141+
142+ //Laravel
143+ GeoIP::getCountryCode();
122144```
123145
124146Get region
125147
126148``` php
127149$geoip->getRegion();
150+
151+ //Laravel
152+ GeoIP::getRegion();
128153```
129154
130155Get region code
131156
132157``` php
133158$geoip->getRegionCode();
159+
160+ //Laravel
161+ GeoIP::getRegionCode();
134162```
135163
136164Get postal code
137165
138166``` php
139167$geoip->getPostalCode();
168+
169+ //Laravel
170+ GeoIP::getPostalCode();
140171```
141172
142173Get timezone
143174
144175``` php
145176$geoip->getTimezone();
177+
178+ //Laravel
179+ GeoIP::getTimezone();
146180```
147181
148182Get 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 99 | Supported: "maxmind", "ip-api"
1010 |
1111 */
12- 'driver ' => 'maxmind ' ,
12+ 'driver ' => 'ip-api ' ,
1313
1414 /*
1515 |--------------------------------------------------------------------------
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments