How to Get Country City Address From Ip Address Laravel 10?




How to Get Country City Address From Ip Address Laravel 10?

Hi dev,

This tutorial will show you how to use Laravel 10 to extract the name of a nation, city, and address from its IP address. I will offer a straightforward example and provide a solution if you have a question regarding laravel 10 location nation city and state from ip. I outlined easily and step-by-step how to use Laravel 10 to obtain a country and city address from an IP address. I'll provide a straightforward example and a solution if you have a question regarding laravel 10 retrieve country name, city name, and address from ip.

The stevebauman/location composer package will be used in this tutorial to retrieve the user's current position within the Laravel application. We will utilise the IP address to determine the nation name, country code, region name, region code, city name, zip code, and latitude and longitude. Simply follow the steps below to obtain the layout shown below.

Step 1: Install Laravel

first of all we need to get fresh Laravel version application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project laravel/laravel blog

Step 2: Install stevebauman/location Package

here, we will install stevebauman/location package for getting current location on login user.

composer require stevebauman/location

Step 3: Create Route

In this is step we need to create some routes for add to cart function.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\UserController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('display-user', [UserController::class, 'index']);

Step 4: Create Controller

in this step, we need to create UserController and add following code on that file:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Stevebauman\Location\Facades\Location;

use Illuminate\View\View;

class UserController extends Controller



* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function index(Request $request): View


/* $ip = $request->ip(); Dynamic IP address */

$ip = ''; /* Static IP address */

$currentUserInfo = Location::get($ip);

return view('user', compact('currentUserInfo'));



Step 5: Create Blade Files

here, we need to create blade file for user. so let's create one by one files:


<!DOCTYPE html>



<meta charset="utf-8">


<link href="" rel="stylesheet">



<div class="container">

<h1>How to Get Current User Location with Laravel -</h1>

<div class="card">

<div class="card-body">


<h4>IP: {{ $currentUserInfo->ip }}</h4>

<h4>Country Name: {{ $currentUserInfo->countryName }}</h4>

<h4>Country Code: {{ $currentUserInfo->countryCode }}</h4>

<h4>Region Code: {{ $currentUserInfo->regionCode }}</h4>

<h4>Region Name: {{ $currentUserInfo->regionName }}</h4>

<h4>City Name: {{ $currentUserInfo->cityName }}</h4>

<h4>Zip Code: {{ $currentUserInfo->zipCode }}</h4>

<h4>Latitude: {{ $currentUserInfo->latitude }}</h4>

<h4>Longitude: {{ $currentUserInfo->longitude }}</h4>







Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:




Country Name: United States

Country Code: US

Region Code: IL

Region Name: illionis

City Name: Chicago

Zip Code:60666

Latitude: 41.9781

Longitude: 87.6298

i hope it can help you...

#Laravel 10