How to get a Client IP address in Laravel

Suresh Ramani - Author - TechvBlogs  Suresh Ramani   Laravel   2 months ago
How to get a Client IP address in Laravel - TechvBlogs

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();

Read Also: What's New in Laravel 9: New Features of Laravel 9 

public function index(Request $request){


$clientIP = \Request::ip();


$clientIP = \Request::getClientIp(true);

Thank you for reading this blog.

Read Also: Laravel 9 Authentication Tutorial

If you want to manage your VPS / VM Server without touching the command line go and  Checkout this linkServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a  matter of minutes.  You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

Laravel PHP

Suresh Ramani - Author - TechvBlogs
Suresh Ramani
Full Stack Developer