public function postFollow(Request $request) { if ($request->input('toggle') == 'u') { $existanceCheck = UserFollows::where('user_id', '=', Auth::user()->id)->where('followed_id', '=', $request->input('user'))->count(); if ($existanceCheck) { $follow = UserFollows::where('user_id', '=', Auth::user()->id)->where('followed_id', '=', $request->input('user'))->first(); $follow->delete(); $user = User::find($request->input('user')); $user->follows--; $user->save(); echo 'ok'; } else { echo 'error'; } } elseif ($request->input('toggle') == 'f') { $existanceCheck = UserFollows::where('user_id', '=', Auth::user()->id)->where('followed_id', '=', $request->input('user'))->count(); if (!$existanceCheck) { $follow = new UserFollows(); $follow->user_id = Auth::user()->id; $follow->followed_id = $request->input('user'); $follow->save(); $user = User::find($request->input('user')); $user->follows++; $user->save(); echo 'ok'; } else { echo 'error'; } } }
public function askIsFollowing($user) { $res = UserFollows::where('user_id', '=', Auth::user()->id)->where('followed_id', '=', $user->id)->count(); return $res > 0; }