Skip to content

Commit

Permalink
refactor: trait HasUpvote to avoid stan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiorodriguesroque committed Nov 9, 2024
1 parent 0497d41 commit f034348
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Traits/HasUpvote.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

trait HasUpvote
{
/**
* Get the votes for parent model.
*
* @return MorphMany<Vote, $this>
*/
public function votes(): MorphMany
{
return $this->morphMany(Vote::class, 'model');
Expand Down Expand Up @@ -67,7 +72,7 @@ public function getUserVote(User $user = null): Vote|null
* Returns a collection of the most recent users who have voted for this item.
*
* @param int $count Displays five users by default.
* @return Collection|\Illuminate\Support\Collection
* @return Collection<int, array{name: string|null, avatar: string|null}>|\Illuminate\Support\Collection<int, array{name: string|null, avatar: string|null}>
*/
public function getRecentVoterDetails(int $count = 5): Collection|\Illuminate\Support\Collection
{
Expand All @@ -78,8 +83,8 @@ public function getRecentVoterDetails(int $count = 5): Collection|\Illuminate\Su
->get()
->map(function ($vote) {
return [
'name' => $vote->user->name,
'avatar' => $vote->user->getGravatar('50'),
'name' => $vote->user?->name,
'avatar' => $vote->user?->getGravatar('50'),
];
});
}
Expand Down

0 comments on commit f034348

Please sign in to comment.