Eslam Zedan
Published in : 2022-03-02
Hello,
I want to get the user location (city - country) from his IP address in Laravel so I can store where he logged in
any recommendations?
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Mohamed Atef Date : 2022-03-03
Best answers
51
Best answers
51
You can use //ipinfo.io/ to get the location details using the IP address in Laravel you can use it easily using GET request to the endpoint like
so in Laravel you can use $req->ip(); to get the IP address of the requests then using HTTP class you can it the endpoint with GET method so the controller will be like
Good luck
Shilpa Date : 2022-03-03
Best answers
10
Best answers
10
There are lots of IP API provider services available in the market. You can use any of them, but make sure below things.
Here is the list of popular IP, City, State, Country, and ISP providers:
//ipapi.co/ ←----- Recommended
//ipapi.com/
//ip-api.com/
//ipwhois.io/
For laravel code, you can use answer given by Mohamed Atef above.
Hope above given information will help you.