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)

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video 📺

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay