How Do You GetThe IP In Middleware

I viewed the docs and figured out how to get a users IP address. This worked from a route, but I can’t use this function in my Middleware.

My middleware code:
`<?php

namespace MyApp\Middleware;

use Psr\Http\Message\RequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

class MyMiddleware extends \MyApp\Container
{

public function __invoke(Request $request, Response $response, $next)
{

    die($request->getAttribute('ip_address'));

    $response = $next($request, $response);
    return $response;

}

}

`

This returns nothing. Is this possible?

Are you using akrabat/rka-ip-address-middleware ?
If so, remember that this middleware needs to run first than the other you want to use the ‘ip_address’. To do this add rka-ip-address-middleware lastly.
Something like:

$app->add(new MyApp\Middleware\MyMiddleware()); 
$app->add(new RKA\Middleware\IpAddress(true, ['10.0.0.1', '10.0.0.2']));

Thank you. I added my middleware to my route group and it worked then, but thanks for that information, I appreciate it.