Skip to content

Commit

Permalink
Merge pull request #41 from salarmotevalli/refactor/HasBeenFavaritedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Sep 13, 2023
2 parents 0052792 + 66682f9 commit e8c31e2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Traits/Favoriteable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait Favoriteable
/**
* @deprecated renamed to `hasBeenFavoritedBy`, will be removed at 5.0
*/
public function isFavoritedBy(Model $user)
public function isFavoritedBy(Model $user): bool
{
return $this->hasBeenFavoritedBy($user);
}
Expand All @@ -25,16 +25,16 @@ public function hasFavoriter(Model $user): bool

public function hasBeenFavoritedBy(Model $user): bool
{
if (\is_a($user, config('auth.providers.users.model'))) {
if ($this->relationLoaded('favoriters')) {
return $this->favoriters->contains($user);
}
if (! \is_a($user, config('auth.providers.users.model'))) {
return false;
}

return ($this->relationLoaded('favorites') ? $this->favorites : $this->favorites())
->where(\config('favorite.user_foreign_key'), $user->getKey())->count() > 0;
if ($this->relationLoaded('favoriters')) {
return $this->favoriters->contains($user);
}

return false;
return ($this->relationLoaded('favorites') ? $this->favorites : $this->favorites())
->where(\config('favorite.user_foreign_key'), $user->getKey())->count() > 0;
}

public function favorites(): \Illuminate\Database\Eloquent\Relations\MorphMany
Expand Down

0 comments on commit e8c31e2

Please sign in to comment.