From f034348ca62e983b53ed8cb89586156f31308b78 Mon Sep 17 00:00:00 2001 From: fabiorodriguesroque Date: Sat, 9 Nov 2024 09:44:34 +0000 Subject: [PATCH] refactor: trait HasUpvote to avoid stan errors --- app/Traits/HasUpvote.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Traits/HasUpvote.php b/app/Traits/HasUpvote.php index f55acaa9..b70ea676 100644 --- a/app/Traits/HasUpvote.php +++ b/app/Traits/HasUpvote.php @@ -12,6 +12,11 @@ trait HasUpvote { + /** + * Get the votes for parent model. + * + * @return MorphMany + */ public function votes(): MorphMany { return $this->morphMany(Vote::class, 'model'); @@ -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|\Illuminate\Support\Collection */ public function getRecentVoterDetails(int $count = 5): Collection|\Illuminate\Support\Collection { @@ -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'), ]; }); }