whereProfileId($profile_id) ->latest() ->get() ->each(function($like) use ($profile_id) { self::set($profile_id, $like->status_id); }); } public static function liked($profileId, $statusId) { $key = self::CACHE_KEY . $profileId; return (bool) Redis::zrank($key, $statusId); } public static function likedBy($status) { $empty = [ 'username' => null, 'others' => false ]; if(!$status) { return $empty; } if(!$status->likes_count) { return $empty; } $like = Like::whereStatusId($status->id)->first(); if(!$like) { return $empty; } $id = $like->profile_id; $res = [ 'username' => ProfileService::get($id)['username'], 'others' => $status->likes_count >= 5, ]; if(request()->user() && request()->user()->profile_id == $status->profile_id) { $res['total_count'] = $status->likes_count; $res['total_count_pretty'] = number_format($res['total_count']); } return $res; } }