/** * Returns the currently logged in User * * @return \App\Eloquent\User|null */ public function user() { try { //Check if user is logged in if (!$this->check()) { //Simply return null return null; } //Get CI super object $ci =& get_instance(); //Get user id from session $userId = $ci->keeper->get('logged_in_user'); //Get the user //SELECT * FROM users WHERE id = $userId $user = User::findOrFail($userId); //Return the user return $user; } catch (Exception $e) { //Unknown error or unexpected results return null; } }
/** * Seed invitations for a user * * @param string $userId */ public function seedInvitations($userId = '') { //Unguard model Model::unguard(); $numRequestToSend = mt_rand(10, 100); //Get the user $user = \App\Eloquent\User::findOrFail($userId); //Get number of users accordingly $users = \App\Eloquent\User::where('id', '!=', $userId)->orderByRaw('RAND()')->limit($numRequestToSend)->get(); //Seed friend request foreach ($users as $someUser) { //Create friend request for user $user->receivedFriendRequests()->create(['sender' => $someUser->id, 'notified' => false]); } echo $numRequestToSend . ' requests created'; Model::reguard(); }
/** * Get a single User using only * his user ID * * @param string $userId * @throws ModelNotFoundException * @return \App\Eloquent\User|null */ public function findUser($userId) { //Return user return $this->user->findOrFail($userId); }