class GeoIp
{
private \SxGeo $sxGeo;
public function __construct()
{
$this->sxGeo = new \SxGeo(Storage::disk('local')->path('sxgeo/SxGeo.dat'));
}
public function getDetectedCountry($ip = null)
{
if (!$ip) {
$ip = real_ip();
}
$countryCode = strtolower($this->sxGeo->getCountry($ip)) ?: 'ru';
return Country::find($countryCode);
}
}