Hello Devs, 

In this tutorial, we will learn Laravel IP Address Using Get Location Example

Many times we need to get visitor's details for security, spam prevention, etc. It's very easy to get the visitor's IP address and their location in PHP Laravel.

Follow this step-by-step guide below. 

Step 1: Install stevebauman/location

composer require stevebauman/location


Step 2: Add providers and aliases

config/app.php

'providers' => [
  ....
  Stevebauman\Location\LocationServiceProvider::class,
],
'aliases' => [
  ....
  'Location' => Stevebauman\Location\Facades\Location::class,
]


Step 3:config with the publish command

php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"


Step 4: Route routes/web.php

Route::get('location','LocationController@index');


Step 5:Controller : app/Http/Controllers/LocationController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;

class LocationController extends Controller
{
  public function index(Request $request)
    {
      $ip= $request->ip();
      $data = \Location::get($ip);
      dd($data);
    }
}


 run the below command for a quick run:

php artisan serve

open bellow URL on your browser:

localhost:8000/location


May this example help you.