被关注着的followers_count要加一 关注着的followings_count也应该加一
如果取消关注 被关注着的followers_count要减一 关注着的followings_count也应该减一
代码如下:
public function follow()
{
$userToFollow = $this->user->byId(request('user'));
$followed = Auth::guard('api')->user()->followThisUser($userToFollow->id);
if(count($followed['attached']) > 0){
$userToFollow->increment('followers_count');
Auth::guard('api')->user()->increment('followings_count');
return response()->json(['followed' => true]);
}
$userToFollow->decrement('followers_count');
Auth::guard('api')->user()->decrement('followings_count');
return response()->json(['followed' => false]);
}