Last active
August 29, 2015 14:14
-
-
Save bcho/3095ce2a426a2dbd6809 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace Vtmer\Blog\Model; | |
| trait PostVisitTrait { | |
| /** | |
| * 增加文章访问量 | |
| * | |
| * @return $this | |
| */ | |
| public function increasePageViews() | |
| { | |
| $this->increments($this->getPageViewsField()); | |
| return $this; | |
| } | |
| /** | |
| * 获取访问量高的文章 | |
| * | |
| * @return \Illumniate\Database\Query | |
| */ | |
| public function scopePopular($query) | |
| { | |
| $threshold = $this->getPopularThreshold(); | |
| return $query->where($this->getPageViewsField(), '>', $threshold); | |
| } | |
| abstract protected function getPageViewsField(); | |
| abstract protected function getPopularThreshold(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment