diff --git a/app/model/PostVisit.php b/app/model/PostVisit.php index 25416e3..bd68cd8 100644 --- a/app/model/PostVisit.php +++ b/app/model/PostVisit.php @@ -42,7 +42,7 @@ class PostVisit extends Model if (empty($value)) { $current_ip = Request::ip(); - $ip = $this->getAttr('ip'); + $ip = $this->getAttr('ip_title'); if ($current_ip == $ip) { $value = '您的IP:' . $ip; @@ -54,6 +54,24 @@ class PostVisit extends Model return $value; } + public function getIpTitleAttr() + { + $value = $this->getAttr('ip'); + + if (empty($value)) { + return $value; + } + + $ip_pieces = explode('.', $value); + + $ip_pieces = array_slice($ip_pieces, 0, -2); + + $ip_pieces[] = '*'; + $ip_pieces[] = '*'; + + return implode('.', $ip_pieces); + } + public function getCreateTimeTitleAttr() { $value = $this->getData('create_time');