In this example, you will get user location information based on their IP address. You need to install a package called stevebauman/location.
The stevebauman/location is an excellent library for detecting a user's location by their IP Address. It has ready-to-use methods for getting user's location data.
By using this package you can get below information:
- Country Name
- Country Code
- Region Name
- Region Code
- City Name
- Zip Code
- ISO Code
- Postal Code
- Metro Code
- Latitude and Longitude
Install stevebauman/location Package
For Installation, you just need to enter below command into the terminal.
Here, we will use this package using import so we don't need to register into our application.
Create Location Controller
Let's create a controller for getting location data and display it using view. First thing you need to enter below command to create a controller :