Files
Epicnabbo-Catalogus-Updated…/Updated_Cms/app/Services/IpLookupService.php
T
Remco 7b9849c159 🆙 More fixes 🆙
2026-01-19 20:43:46 +01:00

35 lines
820 B
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class IpLookupService
{
private string $baseUrl = 'https://api.ipdata.co';
public function __construct(private readonly string $apiKey) {}
/**
* @return array<string, mixed>
*/
public function ipLookup(string $ip): array
{
$response = Http::acceptJson()->get(sprintf('%s/%s?api-key=%s', $this->baseUrl, $ip, $this->apiKey));
/** @var array<string, mixed> $json */
$json = $response->json() ?? [];
if (! $response->ok()) {
$message = array_key_exists('message', $json) ? $json['message'] : 'Unknown error';
return [
'message' => $message,
'status' => $response->status(),
];
}
return $json;
}
}