DEV Community

Cover image for How to get a Client IP address in Laravel
Suresh Ramani
Suresh Ramani

Posted on • Originally published at techvblogs.com

14 1

How to get a Client IP address in Laravel

What is an IP Address?

An Internet Protocol(IP) address also known as a logical address is given by the internet service provider(ISP) which uniquely identifies a system over the network. IP address keeps on changing from time to time.

How to get a Client IP address in Laravel?

For getting the IP Address we have to include use Illuminate\Http\Request; in the controller and then add the code of the below pre tag. It will give the IP address of the network.

$clientIP = request()->ip();
dd($clientIP);
Enter fullscreen mode Exit fullscreen mode
public function index(Request $request){
  dd($request->ip());
}
Enter fullscreen mode Exit fullscreen mode
$clientIP = \Request::ip();
dd($clientIP);
Enter fullscreen mode Exit fullscreen mode
$clientIP = \Request::getClientIp(true);
dd($clientIP);
Enter fullscreen mode Exit fullscreen mode

Thank you for reading this blog.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay