Hello User,
Here we can learn how to get the client's IP address using a Laravel application.
The internet service provider (ISP) assigns an Internet Protocol (IP) address, sometimes referred to as a logical address, which specifically identifies a machine across the network. The IP address is always changing.
We can use Illuminate\Http\Request into the controller in order to obtain the IP address, after which the code listed below must be added.
It will provide the network's IP address. Lets check below code to get client ip address : We can use
$clientIpAddress = request()->ip();
return $clientIpAddress;
Let's give an example of a controller function:
public function getClientIP(Request $request){
return $request->ip();
}
We can use the direct Request method to get the client's IP address :
$clientIpAddress = \Request::ip();
return $clientIpAddress;
You can passing the true parameter inside the ip function parameter. Let see how :
$clientIpAddress = \Request::ip(true);
return $clientIpAddress;