public function getComments(Request $request) { try { $post_id = $request->get('post_id'); $post = Post::find($post_id); $comments = []; $timeAgo = new TimeAgo(); foreach ($post->comments as $comment) { $comments[] = ['id' => $comment->id, 'comment_text' => $comment->comment_text, 'customer_name' => $comment->customer->display_name, 'time_ago' => $timeAgo->inWords($comment->created_at)]; } // sleep(5); return Response::json(['status' => 1, 'message' => 'Success', 'data' => $comments]); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }
public function getPost(Request $request) { try { $session_token = $request->get('session_token'); $post_id = $request->get('post_id'); $post = Post::find($post_id); $data = []; $customer = SessionUtil::getCustomer($session_token); $is_liked = DB::table('post_likes')->where('customer_id', $customer->id)->where('post_id', $post->id)->exists(); $is_photo_post = $post->photo != null && $post->photo != ""; $timeAgo = new TimeAgo(); $data = ['id' => $post->id, 'description' => $post->description, 'photo' => $post->photo, 'like_count' => $post->likes->count(), 'is_liked' => $is_liked, 'is_photo_post' => $is_photo_post, 'comment_count' => $post->comments->count(), 'customer_name' => $post->customer->display_name, 'ago' => $timeAgo->inWords($post->created_at)]; // sleep(5); return Response::json(['status' => 1, 'message' => 'Success', 'data' => $data]); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }
public function getNotifications(Request $request) { try { $session_token = $request->get('session_token'); $index = $request->get('index', 1); $limit = 10; $offset = $index - 1; $notifications = Notification::take($limit)->offset($offset * $limit)->orderBy('created_at', 'DESC')->get(); $data = []; $timeAgo = new TimeAgo(); foreach ($notifications as $notification) { $data[] = ['id' => $notification->id, 'subject' => $notification->subject, 'body' => $notification->body, 'ago' => $timeAgo->inWords($notification->created_at)]; } return Response::json(['status' => 1, 'message' => 'Success', 'data' => $data]); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }