Get the client IP address in Laravel – Fast tips

Valerio Barbera

In this article, I will share with you how to get the client IP address using the Laravel Request class.

You have three options to invoke the \Illuminate\Http\Request class:

// Using the helper function
echo request()->ip();

// Using the Facade
echo \Request::ip();

// Using the underlying method directly
echo \Request::getClientIp(true);

How to use the IP address to monitor your navigation sessions

The Inspector middleware allows you to exlude traffic from your monitoring data with a simple configuration:

/*
 |---------------------------------------------------------------------
 | Web request url to ignore
 |---------------------------------------------------------------------
 |
 | Add at this list the url schemes that you don't want monitoring
 | in your Inspector dashboard. You can also use wildcard expression (*).
 |
 */
 
'ignore_url' => [
    'telescope*',
    'vendor/telescope*',
    'horizon*',
    'vendor/horizon*',
],

If you need to implement a custom logic, the middleware is also designed to be extended.

<?php

use \Inspector\Laravel\Middleware\WebRequestMonitoring;


class InspectorFilterMonitoringMiddleware extends WebRequestMonitoring
{
    /**
     * Determine if Inspector should record current request.
     *
     * @param \Illuminate\Http\Request $request
     * @return bool
     */
    protected function shouldRecorded($request): bool
    {
        // Monitor requests coming from your IP addresses (e.g. for debugging purpose)
        return in_array($request->ip(), ['xxx.xxx.xxx.xxx']);
    }
}

Overwriting the shouldRecorded() method, you can implement a custom condition to decide which routes should be ignored by Inspector.

Check out the complete tutorial in the official documentation:

https://docs.inspector.dev/guides/laravel/http-requests-monitoring#ignore-http-requests

You can follow me on Linkedin or X. I post about building my SaaS business.

Monitor your Laravel application for free

Inspector is a Code Execution Monitoring tool specifically designed for software developers. You don’t need to install anything on the infrastructure, just install the Laravel package and you are ready to go.

Inspector is super easy to use and require zero configurations.

If you are looking for HTTP monitoring, query insights, and the ability to forward alerts and notifications into your preferred messaging environment try Inspector for free. Register your account.

Or learn more on the website: https://inspector.dev

Inspector Code Execution Monitoring

Related Posts

Neuron AI Now Supports ZAI β€” The GLM Series Is Worth Your Attention

There’s a pattern I’ve noticed over the past year while working on Neuron AI: the decisions that matter most are rarely about chasing trends. They’re about quietly recognizing something that works, testing it seriously, and integrating it so that other developers can benefit without having to do that work themselves. That’s the honest story behind

Maestro: A Customizable CLI Agent Built Entirely in PHP

For a long time, the implicit message from the AI tooling industry has been: if you want to build agents, learn Python. The frameworks, the tutorials, the conference talks, all pointed in the same direction. PHP developers who wanted to experiment with autonomous systems had two options: switch stacks or stitch something together from raw

Neuron v3 is Here! πŸš€ Agentic Workflows in PHP

Exactly one year ago, we shared the first public lines of Neuron AI with the world. Six months ago, we stood at the crossroads of V2, refining our vision. Today, we arrive at Version 3 as the first agentic framework of the PHP world. I’m aware that a major release every six months is a