Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sasafister's avatar

Using GeoIp for fetching location

How can i fetch geolocation for user who submit form on website? For example, when someone submit form, i want to display best moods from that specific country?

I found this package https://github.com/torann/laravel-4-geoip and put little snippet

$location = GeoIP::getLocation( );
        dd($location);

but i always recieve US even tough i'm located in Croatia. I put my own IP then i recieve this error

The file "/home/vagrant/howdoyou/app/database/maxmind/GeoLite2-City.mmdb" does not exist or is not readable.

How can i use this package? Do i have to store IP address first in db?

0 likes
7 replies
sasafister's avatar

GeoIP works just fine. I had to download packeg that contains all maps teritory. It works great, and it's very easy to use.

Nasir's avatar

hi @sasafister i am facing the same problem can you please tell me how to solve this

Non-static method Torann\GeoIP\GeoIP::getLocation() should not be called statically Here is my code $ip = $_SERVER['REMOTE_ADDR']; $location = GeoIP::getlocation($ip); dd($location);

sasafister's avatar

@Nasir that was two years ago, I don' remember, but try to read documentation

Nasir's avatar

'Torann\GeoIP\GeoIPServiceProvider', this is the provider i am using 'GeoIP' => 'Torann\GeoIP\GeoIPFacade', this is the alias. Thanks for your time @sasafister

Please or to participate in this conversation.