<?php require_once '../nl-init.php'; require_once '../class/nl-user-class.php'; require_once '../class/nl-auth-class.php'; require_once 'api_headers.php'; $auth = Auth::getInstance(); $userID = $auth->getUserID(); if ($userID <= 0) { return; } if (is_get()) { $user = new User($userID); echo json_encode(array("follows" => $user->follows())); } else { $adminID = _get("adminID", 0); if ($adminID <= 0) { return; } $user = new User($userID); $user->follow($adminID); echo json_encode(array("follows" => $user->follows())); }
/** * Follow a larabook user * * @param $userIdToFollow * @param User $user * @return mixed */ public function follow($userIdToFollow, User $user) { return $user->follows()->attach($userIdToFollow); }
/** * Determine if current user follows another user * * @param User $otherUser * @return bool */ public function isFollowedBy(User $otherUser) { $idsWhoOtherUserFollows = $otherUser->follows()->lists('followed_id'); return in_array($this->id, $idsWhoOtherUserFollows); }
public function set_follows() { self::$follows = get_follows(self::$user_id); }