From a5e64da69bd6e57789c644fa14c0ef90ad4f5eda Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 3 May 2021 17:55:06 -0600 Subject: [PATCH] Update LikeService, fix likedBy method --- app/Services/LikeService.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Services/LikeService.php b/app/Services/LikeService.php index 8ed2bfc3a..36f31ee44 100644 --- a/app/Services/LikeService.php +++ b/app/Services/LikeService.php @@ -50,13 +50,27 @@ class LikeService { public static function likedBy($status) { - if(!$status->likes_count) { - return [ - 'username' => null, - 'others' => false - ]; + $empty = [ + 'username' => null, + 'others' => false + ]; + + if(!$status) { + return $empty; } - $id = Like::whereStatusId($status->id)->first()->profile_id; + + if(!$status->likes_count) { + return $empty; + } + + $like = Like::whereStatusId($status->id)->first(); + + if(!$like) { + return $empty; + } + + $id = $like->profile_id; + return [ 'username' => ProfileService::get($id)['username'], 'others' => $status->likes_count >= 5,