Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saurav77's avatar

How to use IP-API in laravel ?

I am using this API in laravel to get longitude and latitude and city and other information? Its URL is like http://ip-api.com/php/{query} and {query} can be a single IPv4/IPv6 address or a domain name. If you don't supply a query the current IP address will be used. does query mean we have to use an IP address? and how to implement it?

public function authorize(){
 $ip_address=$request->getClientIp();
        $url = "http://ip-api.com/php/";
        $response = $client->request("GET", $url,[
            'query' => $ip_address
        ]);
        $response=(array) json_decode($response->getBody()->getContents());
} 
0 likes
1 reply

Please or to participate in this conversation.