feat: menric
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\CfIpCountry;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PageVisit extends Model
|
||||
@@ -23,6 +24,7 @@ class PageVisit extends Model
|
||||
'browser',
|
||||
'browser_version',
|
||||
'ip',
|
||||
'country',
|
||||
'domain',
|
||||
'referer',
|
||||
'created_at',
|
||||
@@ -133,6 +135,10 @@ class PageVisit extends Model
|
||||
$updates['client_uid'] = substr($uid, 0, 64);
|
||||
}
|
||||
}
|
||||
$incomingCountry = CfIpCountry::normalize(isset($attrs['country']) ? (string) $attrs['country'] : null);
|
||||
if ($incomingCountry && trim((string) ($existing->country ?? '')) === '') {
|
||||
$updates['country'] = $incomingCountry;
|
||||
}
|
||||
foreach (['user_agent', 'os', 'os_version', 'browser', 'browser_version', 'domain', 'referer'] as $field) {
|
||||
$incoming = $attrs[$field] ?? null;
|
||||
if (! is_string($incoming) || trim($incoming) === '') {
|
||||
@@ -153,6 +159,7 @@ class PageVisit extends Model
|
||||
|
||||
$attrs['chain'] = $chain;
|
||||
$attrs['created_at'] = $attrs['created_at'] ?? now();
|
||||
$attrs['country'] = CfIpCountry::normalize(isset($attrs['country']) ? (string) $attrs['country'] : null);
|
||||
|
||||
return static::query()->create($attrs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user