How to get client IP address in Laravel 10?

Mar 07, 2023 . Admin

Hey Dev,

You will learn how to use Laravel 10 to obtain the client's IP address from this comprehensive manual. This post covers Laravel 10 Get IP Address in depth. I'd like to explain to you how to obtain your IP address in Laravel 10. In this lesson, I'll demonstrate how to obtain the client's IP address using Laravel 10.

Here, There are several ways to get ip address in laravel 10 application. I will give 4 ways to get client's IP Addresses in the laravel 10 application.

Example 1:
$clientIP = request()->ip();   
Example 2:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(Request $request)
        $clientIP = $request->ip();   
Example 3:
$clientIP = \Request::ip();
Example 4:
$clientIP = \Request::getClientIp(true);
#Laravel 10