public function likable() { $user_id = User::getCurrentUserId(); //Check if the media was already liked by the user $like = Like::where('media_id', $this->id)->where('user_id', $user_id)->first(); return !(bool) $like; }
public function update($id) { $like = new Like(); $user = Auth::user(); $id = Input::only('story_id'); $like->where('user_id', Auth::id)->where('story_id', $id)->first()->delete(); return Redirect::back(); }
public function removeLike($entry_id) { $user = JWTAuth::parseToken()->authenticate(); $newLike['entry_id'] = $entry_id; $newLike['user_id'] = $user->id; if (Like::where(['entry_id' => $newLike['entry_id'], 'user_id' => $newLike['user_id']])->exists()) { Like::where(['entry_id' => $newLike['entry_id'], 'user_id' => $newLike['user_id']])->delete(); } else { abort(403, 'Like is not registered'); } }
public function viewReadAll() { // Set logged in user to a variable. $authUser = Auth::user(); // Find user's likes in database. $likes = Like::where('user_id', '=', $authUser->id)->latest('id')->get(); // Find all photos in the database. $photos = Photo::all(); // Return view with variables. return view('likes.viewReadAll')->with('likes', $likes)->with('authUser', $authUser)->with('photos', $photos); }
public function postLike(\Illuminate\Http\Request $request) { $id = e($request->input('id')); $course = Course::findOrFail($id); if (Like::where('course', '=', $id)->where('user', '=', \Auth::user()->id)->exists()) { $course->likes--; $like = Like::where('course', '=', $id)->where('user', '=', \Auth::user()->id)->first(); $like->delete(); } else { $course->likes++; $like = new Like(); $like->course = $id; $like->user = Auth::user()->id; $like->save(); } $course->save(); return view::make('courses.liked', compact('course')); }
public function getEntries($challengeType, $challenge_id) { try { $userToken = JWTAuth::parseToken()->authenticate(); $signed_in = true; } catch (\Exception $e) { $signed_in = false; } $challenge = Challenge::find($challenge_id); $entries = $challenge->entries; if ($entries) { foreach ($entries as $entry) { $user = $entry->user; unset($entry->challenge_id); unset($entry->created_at); unset($entry->updated_at); unset($entry->user); $entry->userPic = $user->userPic; $entry->userName = $user->name; $entry->category = $challenge->isWeekly ? 'weekly' : 'monthly'; $entry->likes = $entry->likesCount(); if ($signed_in) { $likes = Like::where('user_id', $userToken->id)->get(); foreach ($likes as $like) { if ($like->entry_id == $entry->id) { $entry->liked = true; } else { $entry->liked = false; } } } } return $challenge; } else { return false; } }
public function userLike(User $user) { $like = Like::where('user_id', $user->id)->where('post_id', $this->id)->first(); return $like; }
public static function hasLiked($iFromWhereID, $iToUserID, $iUserID, $iLikeFromType, $iLikeFromID) { $oResult = Like::where($iFromWhereID, $iLikeFromID)->where('to_user_id', $iToUserID)->where('from_user_id', $iUserID)->where('status', Like::LIKE_STATUS_ACTIVE)->get(); if ($oResult->first()) { return $oResult->first()->toArray(); } else { return false; } }
/** * Toggle tattoo like * * @return View */ public function like(Request $request) { $res = array(); $res['success'] = false; $tattooId = $request->input('id'); $user = Auth::user(); if ($user->likes()->where('tattoo_id', $tattooId)->count()) { $like = Like::where('tattoo_id', $tattooId)->where('user_id', $user->id)->first(); if ($like) { //already liked so unlike now(delete) $like->delete(); $res['data'] = 'Like'; //unlike success now show Like $res['success'] = true; $res['likeCount'] = Like::where('tattoo_id', $tattooId)->count(); } } else { $like = new Like(); $like->tattoo_id = $tattooId; $like->user_id = $user->id; if ($like->save()) { $res['data'] = 'Unlike'; //like success now show Unlike $res['success'] = true; $res['likeCount'] = Like::where('tattoo_id', $tattooId)->count(); } } return $res; }
function setLikeDislike(Request $request) { $user = Session::get('user'); if (!isset($user)) { return Redirect::back(); } if (Like::where('user_id', $user[5])->where('review_id', $request->review_id)->exists()) { Like::where('user_id', $user[5])->where('review_id', $request->review_id)->update(['likeOrDislike' => $request->likeOrDislike]); } else { $likes = new Like(); $likes->user_id = $user[5]; $likes->review_id = $request->review_id; $likes->likeOrDislike = $request->likeOrDislike; $likes->save(); } return redirect('/relogin'); }
function get_comments_by_photo_id() { $iFromType = Input::get('from_type'); $iFromID = Input::get('from_id'); $aLoggedInUser = User::where('id', Session::get('user')['id'])->first()->toArray(); switch ($iFromType) { case Comment::COMMENT_FROM_TYPE_USER: $aFromItem = User::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_CHARACTER: $aFromItem = Character::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_CHARACTER)->where('character_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('character_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_FAMILY: $aFromItem = Family::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_FAMILY)->where('family_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('family_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_SPECY: $aFromItem = Specy::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_SPECY)->where('specy_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('specy_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_PHOTO: $aFromItem = Photo::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_PHOTO)->where('photo_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('photo_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_POST: $aFromItem = Post::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_POST)->where('post_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('post_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; case Comment::COMMENT_FROM_TYPE_MATE: $aFromItem = Mate::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_MATE)->where('mate_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('mate_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; default: $aFromItem = User::where('id', $iFromID)->first()->toArray(); $oItemLikers = Like::where('like_type', Like::LIKE_TYPE_USER)->where('user_id', $aFromItem['id'])->where('status', Like::LIKE_STATUS_ACTIVE)->get(); $aFromItem['likers'] = is_array($oItemLikers->toArray()) && count($oItemLikers->toArray()) ? $oItemLikers->toArray() : []; $aFromItem['logged_in_user']['has_liked'] = LikesController::checkHasLikedInArray($aFromItem['likers'], $aLoggedInUser['id']); $oComments = Comment::where('user_id', $iFromID)->where('status', Comment::COMMENT_STATUS_DEFAULT)->get(); break; } $oComments = is_array($oComments->toArray()) && count($oComments->toArray() > 0) ? $oComments->toArray() : []; $aComments = null; $iFromWhereID = null; for ($i = 0; $i < count($oComments); $i++) { $aComments[$i] = $oComments[$i]; $aComments[$i]['from_user'] = User::where('id', $oComments[$i]['from_user_id'])->first()->toArray(); if ($oComments[$i]['comment_photo_id'] > 0) { $aComments[$i]['photo_comment'] = Photo::where('id', $oComments[$i]['comment_photo_id'])->first()->toArray(); } $iFromType = $oComments[$i]['comment_from_type']; switch ($iFromType) { case Comment::COMMENT_FROM_TYPE_USER: $iFromWhereID = "user_id"; $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_CHARACTER: $iFromWhereID = "character_id"; $aComments[$i]['from'] = Character::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_FAMILY: $iFromWhereID = "family_id"; $aComments[$i]['from'] = Family::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_SPECY: $iFromWhereID = "specy_id"; $aComments[$i]['from'] = Specy::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_PHOTO: $iFromWhereID = "photo_id"; $aComments[$i]['from'] = Photo::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_POST: $iFromWhereID = "post_id"; $aComments[$i]['from'] = Post::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_MATE: $iFromWhereID = "mate_id"; $aComments[$i]['from'] = Mate::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; default: $iFromWhereID = "user_id"; $aComments[$i]['from'] = User::where('id', $oComments[$i][$iFromWhereID])->first()->toArray(); break; } } $view = view('users.comments.show')->with('aComments', $aComments); $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType); if ($oComments) { return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]); } else { $htmlFromWhatView = view('users.comments.partials.partial-comment-from-what-display')->with('aFromItem', $aFromItem)->with('iFromType', $iFromType); $view = view('users.comments.show')->with('aComments', []); if ($htmlFromWhatView != "") { return response()->json(['view' => (string) $view, 'status' => true, 'message' => "Successfully archived character", 'what_to_display' => (string) $htmlFromWhatView]); } else { echo json_encode(array('status' => false, 'message' => "Something went wrong. Please try again later")); } } die; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($user_id, $tweet_id) { $like = Like::where('user_id', $user_id)->where('tweet_id', $tweet_id); $like->delete(); return redirect()->back(); }
public function getLikesCountAttribute() { return Like::where('user_id', $this->id)->count(); }
public function destroy($id) { $comment = Comment::where('form_id', $id)->delete(); $form = Form::where('id', $id)->delete(); $like = Like::where('form_id', $id)->delete(); return redirect('/form'); }
public function is_liked_by($user) { return Like::where('tweet_id', $this->id)->where('user_id', $user->id)->first(); }
public function get_details() { $iLimit = 10; $iOffset = 0; if (Input::get('iOffset')) { $iOffset = Input::get('iOffset'); } $htmlView = ""; $bLoggedInUser = Session::has('user'); if ($bLoggedInUser) { $aLoggedInUser['user'] = User::where('id', Session::get('user')['id'])->first()->toArray(); $aLoggedInUser['current_character'] = Character::where('id', $aLoggedInUser['user']['current_character_id'])->first()->toArray(); } //$aMate = Mate::query("SELECT * FROM mates WHERE ((from_user_id = 10 OR to_user_id = 10) AND (status = 8 OR status = 9))")->get()->toArray(); $aMates = DB::select(DB::raw("SELECT * FROM mates WHERE ((from_user_id = " . $aLoggedInUser['user']['id'] . " OR to_user_id = " . $aLoggedInUser['user']['id'] . ") AND (status = " . Mate::MATE_STATUS_ACCEPTED_BY_ADMIN . " OR status = " . Mate::MATE_STATUS_ACCEPTED_BY_USER . "))")); $aUserID = []; $sUserIDS = ""; foreach (json_decode(json_encode($aMates), true) as $aMate) { if ($aMate['from_user_id'] != $aLoggedInUser['user']['id']) { $aUserID[] = $aMate['from_user_id']; $sUserIDS = $sUserIDS . $aMate['from_user_id'] . ", "; } else { $aUserID[] = $aMate['to_user_id']; $sUserIDS = $sUserIDS . $aMate['to_user_id'] . ", "; } } $sUserIDS = substr($sUserIDS, 0, -2); /* $aData = DB::select(DB::raw("SELECT characters.*, comments.*, likes.*, mates.*, posts.*, users.* FROM users LEFT JOIN characters on users.id = characters.user_id LEFT JOIN comments on (characters.user_id = comments.from_user_id OR characters.user_id = comments.to_user_id) LEFT JOIN likes on (comments.from_user_id = likes.from_user_id OR comments.from_user_id = likes.to_user_id OR comments.to_user_id = likes.from_user_id OR comments.to_user_id = likes.to_user_id) LEFT JOIN mates on (likes.from_user_id = mates.from_user_id OR likes.from_user_id = mates.to_user_id OR likes.to_user_id = mates.from_user_id OR likes.to_user_id = mates.to_user_id) LEFT JOIN posts on (likes.from_user_id = posts.from_user_id OR likes.from_user_id = posts.to_user_id OR likes.to_user_id = posts.from_user_id OR likes.to_user_id = posts.to_user_id OR likes.from_user_id = posts.user_id OR likes.to_user_id = posts.user_id) WHERE users.id = " . $aLoggedInUser['user']['id'] . " ORDER BY comments.date_updated, likes.date_updated, likes.date_updated, mates.date_updated, posts.date_updated ASC"));*/ $oUpdates = DB::select(DB::raw("SELECT * FROM updates WHERE\n status = " . Update::UPDATE_STATUS_ACTIVE . " OR\n status = " . Update::UPDATE_STATUS_ACTIVATED_BY_USER . " OR\n status = " . Update::UPDATE_STATUS_ACTIVATED_BY_ADMIN . " AND\n user_id IN (" . $sUserIDS . ")\n ORDER BY id DESC\n LIMIT {$iOffset}, {$iLimit}")); $aUpdates = json_decode(json_encode($oUpdates), true); for ($i = 0; $i < count($aUpdates); $i++) { $aUpdates[$i]['user'] = User::where('id', $aUpdates[$i]['user_id'])->first()->toArray(); switch ($aUpdates[$i]['update_type']) { case Update::UPDATE_TYPE_USER: break; case Update::UPDATE_TYPE_SPECY: break; case Update::UPDATE_TYPE_FAMILY: break; case Update::UPDATE_TYPE_CHARACTER: $aUpdates[$i]['character'] = Character::where('id', $aUpdates[$i]['character_id'])->first()->toArray(); break; case Update::UPDATE_TYPE_MATE: break; case Update::UPDATE_TYPE_COMMENT: $aUpdates[$i]['comment'] = Comment::where('id', $aUpdates[$i]['comment_id'])->first()->toArray(); $aUpdates[$i]['comment']['from_user'] = User::where('id', $aUpdates[$i]['comment']['from_user_id'])->first()->toArray(); $aUpdates[$i]['comment']['to_user'] = User::where('id', $aUpdates[$i]['comment']['to_user_id'])->first()->toArray(); switch ($aUpdates[$i]['comment']['comment_from_type']) { case Comment::COMMENT_FROM_TYPE_USER: break; case Comment::COMMENT_FROM_TYPE_CHARACTER: break; case Comment::COMMENT_FROM_TYPE_FAMILY: break; case Comment::COMMENT_FROM_TYPE_SPECY: break; case Comment::COMMENT_FROM_TYPE_PHOTO: $aUpdates[$i]['comment']['photo'] = Photo::where('id', $aUpdates[$i]['comment']['photo_id'])->first()->toArray(); break; case Comment::COMMENT_FROM_TYPE_POST: break; case Comment::COMMENT_FROM_TYPE_MATE: break; } $htmlView = $htmlView . (string) view('users.pages.partials.comment-show')->with('aUpdate', $aUpdates[$i]); break; case Update::UPDATE_TYPE_PHOTO: break; case Update::UPDATE_TYPE_LIKE: $aUpdates[$i]['like'] = Like::where('id', $aUpdates[$i]['like_id'])->first()->toArray(); break; case Update::UPDATE_TYPE_POST: $aUpdates[$i]['post'] = Post::where('id', $aUpdates[$i]['post_id'])->first()->toArray(); break; } } return response()->json(['status' => true, 'message' => "Successfully submitted comment", 'view' => (string) $htmlView]); }
public function getUnlikeCountAttribute() { return Like::where('proposal_id', $this->id)->where('like', 0)->count(); }
public function storeLike(Request $request, $name) { $data = $request->all(); if ($data['like'] == "true") { $data['like'] = true; } else { $data['like'] = false; } $data['user_id'] = Auth::user()->id; //CHECK WHETHER LIKED OR DISLIKED AND REACT ACCORDINGLY $likeObject = new Like(); $isLike = $likeObject->isLike($data['user_id'], $data['post_id']); $isDislike = $likeObject->isDislike($data['user_id'], $data['post_id']); if (!$isLike && !$isDislike) { //if not liked and not disliked Like::create($data); } elseif ($isLike && !$isDislike && $data['like'] == true) { //already liked,not disliked,pressed like button //dd("already liked,not disliked,pressed like button"); Like::where(['post_id' => $data['post_id'], 'user_id' => $data['user_id']])->delete(); } elseif ($isLike && !$isDislike && $data['like'] == false) { //already liked,not disliked,but pressed dislike button //dd("already liked,not disliked,but pressed dislike button"); Like::where(['post_id' => $data['post_id'], 'user_id' => $data['user_id']])->update(array('like' => false)); } elseif (!$isLike && $isDislike && $data['like'] == true) { //not liked,already disliked,but pressed like button //dd("not liked,already disliked,but pressed like button"); Like::where(['post_id' => $data['post_id'], 'user_id' => $data['user_id']])->update(array('like' => true)); } elseif (!$isLike && $isDislike && $data['like'] == false) { //not liked,already disliked,but pressed dislike button //dd("not liked,already disliked,but pressed dislike button"); Like::where(['post_id' => $data['post_id'], 'user_id' => $data['user_id']])->delete(); } $post = Post::find($data['post_id']); $countLikeDislike = null; $countLikeDislike['likes'] = $post->Likes()->count(); $countLikeDislike['dislikes'] = $post->Dislikes()->count(); $countLikeDislike['icon_flag'] = $data['like']; return $countLikeDislike; }
public function likeUnlike($id, $action) { //Get Proposal $proposal = $this->proposalsRepository->find($id); //Get User if (!Auth::check()) { // The user is not logged in... // Retrieve UUID from Cookie $user_id = null; $unique = Cookie::get('uuid'); } else { //Retrieve UUID from User $user_id = Auth::user()->id; $unique = Auth::user()->uuid; } //Possible Values: Null, 0 or 1 $existing_like = Like::where('uuid', $unique)->where('proposal_id', $id)->value('like'); switch ($existing_like) { // Already Unliked case '0': switch ($action) { case 'like': Like::where('uuid', $unique)->where('proposal_id', $id)->update(['like' => $action == 'like']); Session::flash('flash_msg', 'Você voltou a curtir essa Ideia Legislativa!'); break; case 'unlike': Session::flash('error_msg', 'Você já deixou de curtir essa Ideia Legislativa!'); break; } break; // Already Liked // Already Liked case '1': switch ($action) { case 'like': Session::flash('error_msg', 'Você já curtiu essa Ideia Legislativa!'); break; case 'unlike': Like::where('uuid', $unique)->where('proposal_id', $id)->update(['like' => $action == 'like']); Session::flash('flash_msg', 'Você deixou de curtir essa Ideia Legislativa!'); break; } break; // New Like // New Like case null: //dd($existing_like, $action, $str_action); Like::create(['user_id' => $user_id, 'uuid' => $unique, 'proposal_id' => $proposal->id, 'like' => $action == 'like', 'ip_address' => Request::ip()]); $approval_url = route('proposal.approval', $id); $msg = 'Sua curtida foi computada com sucesso. Caso queira apoiar oficialmente esta proposta, <a href="' . $approval_url . '">clique aqui</a>.'; Session::flash('flash_msg', $msg); break; } return redirect()->back(); }