Skip to content

Commit

Permalink
feat: separate love into a separate trait
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Sep 24, 2024
1 parent 4095252 commit fff42ae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
47 changes: 47 additions & 0 deletions src/HasLove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace CSlant\LaravelLike;

use CSlant\LaravelLike\Enums\LikeTypeEnum;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;

/**
* Trait HasLove
*
* @package CSlant\LaravelLike
* @mixin Model
*/
trait HasLove
{
/**
* The scope locale for select love relationship.
*
* @return MorphOne
*/
public function loveTo(): MorphOne
{
return $this->likeOne()->where('type', LikeTypeEnum::LOVE);
}

/**
* The scope locale for select loves relationship.
*
* @return MorphMany
*/
public function lovesTo(): MorphMany
{
return $this->likes()->where('type', LikeTypeEnum::LOVE);
}

/**
* Get the count of loves.
*
* @return int
*/
public function lovesCount(): int
{
return $this->lovesTo()->count();
}
}
10 changes: 0 additions & 10 deletions src/Traits/LikeCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public function dislikesCount(): int
return $this->dislikesTo()->count();
}

/**
* Get the count of loves.
*
* @return int
*/
public function lovesCount(): int
{
return $this->lovesTo()->count();
}

/**
* Get digital count.
*
Expand Down

0 comments on commit fff42ae

Please sign in to comment.