/**
  * Store a newly created Comment in storage.
  *
  * @param CreateCommentRequest $request
  *
  * @return Response
  */
 public function store(CreateCommentRequest $request)
 {
     $input = $request->all();
     $comment = $this->commentRepository->create($input);
     Flash::success('Comment saved successfully.');
     return redirect(route('comments.index'));
 }
 /**
  * Store a newly created Comment in storage.
  * POST /comments
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(Comment::$rules) > 0) {
         $validator = $this->validateRequestOrFail($request, Comment::$rules);
         if ($validator) {
             return $validator;
         }
     }
     $input = $request->all();
     $input['objectId'] = str_random(10);
     $comments = $this->commentRepository->create($input);
     if (isset($input['postType']) && $input['postType'] == 'iWomenPost') {
         $post = IwomenPost::where('objectId', $input['postId'])->first();
         if ($post) {
             $post->comment_count = $post->comment_count + 1;
             $post->update();
         }
     } else {
         if (isset($input['postType']) && $input['postType'] == 'Post') {
             $post = Post::where('objectId', $input['postId'])->first();
             if ($post) {
                 $post->comment_count = $post->comment_count + 1;
                 $post->update();
             }
         } else {
             if (isset($input['postType']) && $input['postType'] == 'SubResourceDetail') {
                 $post = SubResourceDetail::where('objectId', $input['postId'])->first();
                 if ($post) {
                     $post->comment_count = $post->comment_count + 1;
                     $post->update();
                 }
             } else {
                 if (isset($input['postType']) && $input['postType'] == 'Resources') {
                     $post = Resources::where('objectId', $input['postId'])->first();
                     if ($post) {
                         $post->comment_count = $post->comment_count + 1;
                         $post->update();
                     }
                 }
             }
         }
     }
     if (isset($input['postType']) && $input['postType'] == 'Post' || isset($input['postType']) && $input['postType'] == 'SubResourceDetail' || isset($input['postType']) && $input['postType'] == 'Resources') {
         if (isset($post) && $post) {
             $device_list = [];
             $gcm = Gcm::where('user_id', $post->userId)->first();
             if ($gcm) {
                 $device_list[] = PushNotification::Device($gcm->reg_id);
                 $message['title'] = 'New Comment';
                 $message['message'] = $comments->comment_contents;
                 $devices = PushNotification::DeviceCollection($device_list);
                 $message = PushNotification::Message(json_encode($message), array());
                 $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message);
             }
         }
     }
     $comments['comment_count'] = $post->comment_count;
     return $this->sendResponse($comments->toArray(), "Comment saved successfully");
 }