Laravel 8 Get Country, City Name & Address From IP Address Example

In this tutorial you will learn about the Laravel 8 Get Country, City Name & Address From IP Address Example and its application with practical example.

In this Laravel 8 get country name, country code, city name, and address from user IP address example tutorial I will show you how to get country name, country code, city name, and address from user IP address in laravel 8. In this tutorial you will learn to get country name, country code, city name, and address from user IP address in laravel 8. When you working on web development project you come to situation where you may want to fetch user information such as country Name, country Code, region Code, region Name, city Name, zip Code, iso Code, postal Code, latitude, longitude, metro Code, metro Code from ip address in laravel 8. In this example I will help you to fetch user info from IP their ip address. We will be using stevebauman/location package in this example to fetch country name, country code, city name, and address from IP address.

Laravel 8 Get Country, City Name & Address From IP Address Example

In this step by step tutorial I will demonstrate you with example to fetch country name, country code, city name, and address from IP address. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install “stevebauman/location”
  • Step 4 – Add Routes
  • Step 5 – Create Controller By Command
  • Step 6 – Start Development Server

Step 1 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2 – Connecting App to Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3 – Install “stevebauman/location”

In this step, we will install stevebauman/location Package via the composer dependency manager. Use the following command to install stevebauman/location Package.

Then, Go to config directory and open app.php file. And register this package into laravel 8 app by adding the following code into your app.php file:

Now you need to run the following command on terminal to publish config/location.php file:

Step 4 – Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 5 – Create Controller By Command

Now, lets create a controller named GeoLocationController using command given below –

Now, go to app\Http\Controllers and open GeoLocationController.php file. Then put the following code into your GeoLocationController.php file:

Step 6 – Start Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 8 Get Country, City Name & Address From IP Address Example and its application with practical example. I hope you will like this tutorial.