install
This commit is contained in:
28
app/Modules/IpStack/Repositories/IpStackRepository.php
Normal file
28
app/Modules/IpStack/Repositories/IpStackRepository.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\IpStack\Repositories;
|
||||
|
||||
use Stevebauman\Location\Facades\Location;
|
||||
|
||||
class IpStackRepository
|
||||
{
|
||||
/**
|
||||
* Get ip stack
|
||||
*/
|
||||
public static function isLocalIp(string $ip): bool
|
||||
{
|
||||
return ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country code from ip
|
||||
*/
|
||||
public static function getCountryCodeFromIp(?string $ip): string
|
||||
{
|
||||
if (is_null($ip)) {
|
||||
return 'TM';
|
||||
}
|
||||
|
||||
return self::isLocalIp($ip) ? 'TM' : Location::get($ip)->countryCode ?? 'TM';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user