public function getGroupPostByID() { $input = Input::all(); $groupid = $input['groupid']; $postid = $input['postid']; $authuser = Auth::user(); if (Input::has('limitfrom')) { $skip = Input::get('limitfrom'); } else { $skip = 0; } $group = Group::find($groupid); if (is_null($group)) { return Response::json(array('success' => false, 'errors' => 'Group not found'), 400); // 400 being the HTTP code for an invalid request. } //Now fetch all the posts belong to that group $posts = Post::orderBy('id', 'DESC')->where('id', $postid)->take(1)->skip($skip)->get(); foreach ($posts as $post) { $task = Task::orderBy('id', 'DESC')->where('id', $post->task_id)->take(1)->get(); $post->task_title = $task[0]->name; $post->task_content = $task[0]->description; $post->display_mission = $post->display_mission; $post->status = $post->status; $post->status_text = $post->filterStatus(); $post->image = ($post->statustype = 'image') ? $post->displayMediaApi() : ''; $post->screenhandle = User::find($post->user_id)->screenhandle; $post->firstname = User::find($post->user_id)->firstname; $post->lastname = User::find($post->user_id)->lastname; $post->comments = $post->getAPIComments(); $user = User::find($post->user_id); $post->userImage = $user->APIGetPictureSrc(); $post->likeCount = count(Like::orderBy('id', 'DESC')->where('post_id', $post->id)->get()); if ($authuser->hasLike($post->id)) { $post->like = true; } else { $post->like = false; } } return $posts->toJson(); }