/** * Stop following specified contributor. * * @param Request $request * @return \Illuminate\Http\Response */ public function unfollow(Request $request) { $contributor_id = $request->input('contributor_id'); $following_id = $request->input('following_id'); $follower = Follower::whereContributorId($contributor_id)->whereFollowing($following_id)->first(); if (count($follower) > 0) { $contributor = Contributor::findOrFail($contributor_id)->name; $following = Contributor::findOrFail($following_id)->name; if ($follower->delete()) { return response()->json(['request_id' => uniqid(), 'status' => 'success', 'message' => $contributor . ' is stop following ' . $following, 'timestamp' => Carbon::now()]); } return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => Lang::get('alert.database.generic'), 'timestamp' => Carbon::now()], 500); } return response()->json(['request_id' => uniqid(), 'status' => 'denied', 'message' => 'You has not followed this contributor before', 'timestamp' => Carbon::now()], 400); }
/** * Stop following specified contributor. * * @param Request $request * @param int $id * @return \Illuminate\Http\Response */ public function unfollow(Request $request, $id) { /* * -------------------------------------------------------------------------- * Perform unfollow request * -------------------------------------------------------------------------- * This operation only for authenticate user, a contributor stop following * another contributor, populate the data and make sure there is following * record from contributor A to B before then perform delete the relation. */ if (Auth::check() && $request->ajax()) { $follower = Follower::whereContributorId(Auth::user()->id)->whereFollowing($id)->first(); if (count($follower) > 0) { if ($follower->delete()) { return response('success'); } return response('failed', 500); } else { return response('success'); } } else { return response('restrict', 401); } }