Laravel 9 Get Country City Name & Address From IP Address Example

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

In this Laravel 9 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 9. In this tutorial you will learn to get country name, country code, city name, and address from user IP address in laravel 9. 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 9. 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 9 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:

  • Install Laravel 9
  • Connecting App to Database
  • Install “stevebauman/location”
  • Add Routes
  • Create Controller By Command
  • Start Development Server

Install Laravel 9

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

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.

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 9 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:

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

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:

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 9 Get Country City Name & Address From IP Address Example and its application with practical example. I hope you will like this tutorial.