Skip to content

Commit

Permalink
feat: using count digital helper to get new count type for like model
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Sep 24, 2024
1 parent 6ab8302 commit 8985921
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/HasLove.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ public function lovesCount(): int
{
return $this->lovesTo()->count();
}

/**
* Get the count of loves in digital format.
*
* @return string
*/
public function lovesCountDigital(): string
{
return count_digital($this->lovesCount());
}
}
24 changes: 2 additions & 22 deletions src/Traits/Like/LikeCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,14 @@ public function dislikesCount(): int
return $this->dislikesTo()->count();
}

/**
* Get digital count.
*
* @param $count
*
* @return string
*/
public function countDigital($count): string
{
if ($count < 1000) {
return $count;
}

if ($count < 1000000) {
return round($count / 1000, 1) . 'K';
}

return round($count / 1000000, 1) . 'M';
}

/**
* Get the count of likes in digital format.
*
* @return string
*/
public function likesCountDigital(): string
{
return $this->countDigital($this->likesCount());
return count_digital($this->likesCount());
}

/**
Expand All @@ -73,6 +53,6 @@ public function likesCountDigital(): string
*/
public function dislikesCountDigital(): string
{
return $this->countDigital($this->dislikesCount());
return count_digital($this->dislikesCount());
}
}

0 comments on commit 8985921

Please sign in to comment.