示例#1
0
 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';
         }
     }
 }
示例#2
0
文件: User.php 项目: MRH4287/fanfic
 public function askIsFollowing($user)
 {
     $res = UserFollows::where('user_id', '=', Auth::user()->id)->where('followed_id', '=', $user->id)->count();
     return $res > 0;
 }