/** * Display the specified resource. * * @param int $itemId * @param string $key * @return Response */ public function show($itemId, $key) { // $retVal = array('status' => 'ERR', 'msg' => 'Invalid Session'); try { $user = \Member::where('session_key', '=', $key)->exists(); if (!$user) { return Response::json($retVal); } $like = \Likes::where('itemid', '=', $itemId)->get(); if ($like->count() > 0) { $retVal = array('status' => 'OK', 'count' => $like->count(), 'itemid' => $itemId, 'itemtype' => $like[0]->itemtype); } else { $retVal = array('status' => 'ERR', 'msg' => 'beyond your imagination :)'); } return Response::json($retVal); } catch (ModelNotFoundException $e) { } }
public function like() { if (Input::has("post_id")) { $post_id = explode("_", Input::get("post_id")); //Find if user already liked the post if (Likes::where("post_id", $post_id[1])->where("user_id", "1")->count() > 0) { Likes::where("post_id", $post_id[1])->where("user_id", "1")->delete(); return Response::json(array("result" => "1", "isunlike" => "0", "text" => "Like")); } else { $like = new Likes(); //We are using hardcoded user id for now , in production change //it to Sentry::getId() if using Sentry for authentication $like->user_id = "1"; $like->post_id = $post_id[1]; $like->save(); return Response::json(array("result" => "1", "isunlike" => "1", "text" => "unlike")); } return Response::json(array("result" => "1", "isunlike" => "1", "text" => "unlike")); } else { //No post id no access sorry return Response::json(array("result" => "0")); } }