/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request, $id) { $data = []; $like = Likes::where('post_id', $id)->where('user_id', $request->user()->id); if ($like) { $like->delete(); } else { // $data['errors'] = "No permission"; // ubavo bi bilo so errori } // return redirect('/home')->with($data); }
/** * get liked back status to determine whether user and visitor have liked * each other. * * @param object $request * * * @return json */ public function likedbackstatus(Request $request) { $username = $request->username; $visitorUsername = $request->visitorusername; try { $result = Likes::where('user1', $visitorUsername)->where('user2', $username)->get(); if (!$result->isEmpty()) { return response()->json(['liked' => true], 200); } else { return response()->json(['liked' => false], 200); } } catch (Illuminate\Database\QueryException $e) { return response()->json(['status' => 200], 200); } }
public function checkLikes() { $userId = $this->request->input('userid'); $friendId = $this->request->input('friendid'); $UData = User::where('id', $friendId)->first(); if ($UData) { $Favorite = Likes::where('like_person', $friendId)->where('like_by', $userId)->first(); if ($Favorite) { $Response = array('success' => '1'); } else { $Response = array('success' => '0'); } return json_encode($Response); } else { echo 'not found'; } }
public function loadPostsByUser(Request $request, $id) { $posts = Posts::where('user_id', $id)->orderBy('created_at', 'desc')->get(); // bidejkji vo baza chuvame samo ime na slika, foreach ($posts as $key => $post) { // slika na user $post->user = $post->author; // za sekoj user koj go postavil komentarot ima $imgName = $post->user->profile_picture; if ($imgName != "") { $imgData = base64_encode(File::get('uploads/profile_pictures/thumbnails/' . $imgName)); } else { $post->user->profile_picture = base64_encode(File::get('uploads/profile_pictures/profile_picture.png')); } $imgData = base64_encode(File::get('uploads/profile_pictures/thumbnails/' . $imgName)); $post->user->profile_picture = $imgData; // slika na post $imgName = $post->post_picture; if ($imgName != "") { $imgData = base64_encode(File::get('uploads/posts/' . $imgName)); $post->post_picture = $imgData; } // komentari $comments = $post->comments; // dodaj gi site likes na ovoj post vo response-ot samo kako brojka (poseben servis za koi useri :)) $post->nComments = count($comments); $post->nLikes = count($post->likes); // za sekoj post, vo odnos na toa koj user e avtenticiran t.e. go napravil requestot, pushti mu // flagche dali vekje go lajknal postot ili ne, za da mozhe da se sredi soodvetno vo angular :) if (count(Likes::where('post_id', $post->id)->where('user_id', $request->user()->id)->get()) == 1) { // povekje e greshka $post->liked = true; } else { $post->liked = false; } } return response()->json(['posts' => $posts]); }
public function likeOrDislike(Request $request) { if (Auth::check()) { $playlist_video_id = $request->playlist_video_id; $playlistVideo = PlaylistVideo::find($playlist_video_id); $value = $request->value; $user = Auth::user(); $line = Likes::where('user_id', $user->id)->where('video_id', $playlist_video_id)->first(); $bddValue = empty($line) ? false : $line->value; if ($value != $bddValue) { $query = $user->likes($playlist_video_id, $value); if ($bddValue == 1) { $playlistVideo->score += -2; } elseif ($bddValue == -1) { $playlistVideo->score += 2; } else { $playlistVideo->score += $value; } } else { $query = $user->likes($playlist_video_id, 0); if ($bddValue == 1) { $playlistVideo->score += -1; } elseif ($bddValue == -1) { $playlistVideo->score += 1; } else { $playlistVideo->score += -$value; } } $playlistVideo->save(); $playlistVideo = PlaylistVideo::with(['numberOfLikes' => function ($query) { $query->get(['value']); }])->find($playlist_video_id); return response()->json($playlistVideo); } }