Laravel 9 - How to Get IP Address?


Share:
 | Published By: Admin | Published On: Mar 04, 2022 | Category: Laravel 9

Hi dev,

Today i will explained to the laravel 9 get client ip address code example. we will demonstrate you diverse strategy for get ip address. in many application you need to get user ip address in laravel 9 application. so, here i share with you some simple example how to get ip address in laravel 9 application. In this example, i will show you how to get current user ip address in laravel 9 controller file. You can simply get client ip address from request object in laravel 9.

How to get Client IP address in Laravel 9 is so easy to use.so you can just follow my step by step and learn How to get Client IP address in Laravel.

So let's see the bellow example.

Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Example 1:
$clientIP = request()->ip();   
   
dd($clientIP);
Example 2:
<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
  
class ClientIpController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $clientIP = $request->ip();   
        dd($clientIP);
    }
}
Example 3:
$clientIP = \Request::ip();
  
dd($clientIP);
Example 4:
$clientIP = \Request::getClientIp(true);
  
dd($clientIP);

I hope it can help you...

Share: