-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate love into a separate trait
- Loading branch information
Showing
2 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
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(); | ||
} | ||
} |
This file contains 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