How to Get Client IP Address in Laravel
Hello Artisans, today I'll show you how to get Client IP Address in our Laravel app. Laravel request() helper method provides us the simpler ways to get the Client IP address. Two methods are:
$method1 = request()->ip();
$method2 = request()->getClientIp();
So if we write this in our controller you dd() this methods, it'll look like below
app/Http/Controllers/HomeController.php
<?php
namespace App\Http\Controllers;
class AdminController extends Controller
{
public function dashboard()
{
$method1 = request()->ip();
$method2 = request()->getClientIp();
dd($method1,$method2);
}
}
Where both methods will print the Client IP Address
Hope it'll help. Thanks for reading. ?