X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d39fc843019b9a4b7d7eebc7544edb8c86e245db..refs/pull/1462/head:/app/Entities/Entity.php diff --git a/app/Entities/Entity.php b/app/Entities/Entity.php index 7917f83f8..482d21766 100644 --- a/app/Entities/Entity.php +++ b/app/Entities/Entity.php @@ -102,6 +102,11 @@ class Entity extends Ownable return $this->morphMany(View::class, 'viewable'); } + public function viewCountQuery() + { + return $this->views()->selectRaw('viewable_id, sum(views) as view_count')->groupBy('viewable_id'); + } + /** * Get the Tag models that have been user assigned to this entity. * @return \Illuminate\Database\Eloquent\Relations\MorphMany @@ -229,7 +234,7 @@ class Entity extends Ownable if (mb_strlen($text) > $length) { $text = mb_substr($text, 0, $length-3) . '...'; } - return trim($text); + return trim($text); } /**