public function getAllPhoto($user_id) { $numTotalPost = $this->countNumPostTowWeek(); $images = DB::table("images")->join('users', 'images.user_id', '=', 'users.id')->leftJoin('likes', function ($join) use($user_id) { $join->on('images.id', '=', 'likes.image_id')->where('likes.user_id', '=', $user_id); })->select('users.id as user_id', 'users.last_name as user_lastname', 'users.first_name as user_firstname', 'users.avatar as avatar', 'likes.id as like_id', 'likes.user_id as userLikeId', 'images.*')->orderBy('images.created_at', 'desc')->take($numTotalPost)->get(); $i = 0; while ($i < $numTotalPost) { $totalLike = LikeFacade::getLike($images[$i]->id); $totalComment = CommentFacade::getAllCommentOfImage($images[$i]->id); $data = ['user_id' => $user_id, 'user_id_image' => $images[$i]->user_id]; $images[$i]->follow = FollowFacade::checkFollow($data); if (!empty($totalLike)) { $images[$i]->likeTotal = []; $images[$i]->likeTotal = $totalLike; } if (count($totalComment) > 0) { $images[$i]->commentTotal = $totalComment; } $i++; } return $images; }
public function checkFollow($data) { $data['user_id_image'] = $this->getUserIdOfImage($data['image_id']); return $result = FollowFacade::checkFollow($data); }