/**
  * Store a newly created SubResourceDetailLike in storage.
  * POST /subResourceDetailLikes
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(SubResourceDetailLike::$rules) > 0) {
         $this->validateRequestOrFail($request, SubResourceDetailLike::$rules);
     }
     $input = $request->all();
     $subResourceDetailLikes = $this->subResourceDetailLikeRepository->create($input);
     $post = SubResourceDetail::find($input['postId']);
     if ($post) {
         $post->likes = $post->likes + 1;
         $post->update();
     } else {
         return response()->json("Invalid iWomen Post Id!", 400);
     }
     return response()->json($post->likes);
 }
Ejemplo n.º 2
0
 public function share($id, Request $request)
 {
     $post_type = $request->input('postType');
     switch ($post_type) {
         case 'Post':
             $post = Post::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'iWomenPost':
             $post = IwomenPost::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'Resources':
             $post = Resources::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         case 'SubResourceDetail':
             $post = SubResourceDetail::find($id);
             if ($post) {
                 $post->share_count = $post->share_count + 1;
                 $post->update();
                 return response()->json($post->share_count);
             }
             break;
         default:
             # code...
             break;
     }
     return response()->json("Successfully shared your post!");
 }