/**
  * Returns the feeds for a user
  *
  * @param \App\Eloquent\User $user
  * @param int $numberPerPage
  * @return \Illuminate\Pagination\LengthAwarePaginator|null
  */
 public function feeds($user = null, $numberPerPage = 3)
 {
     try {
         //Get CI super object
         $ci =& get_instance();
         //Calculate page
         $page = $ci->input->get('page') !== false ? $ci->input->get('page') : 1;
         //Count the posts
         $postsCount = $this->post->with(['user'])->whereHas('user', function ($query) use($user) {
             $query->whereIn('id', $user->friends()->lists('users.id')->merge([$user->id])->all());
         })->count();
         //No posts found
         if ($postsCount == 0) {
             //Return null
             return null;
         }
         //Limiting posts
         $limitsPosts = $this->post->with(['user'])->whereHas('user', function ($query) use($user) {
             $query->whereIn('id', $user->friends()->lists('users.id')->merge([$user->id])->all());
         })->skip($numberPerPage * ($page - 1))->take($numberPerPage)->orderBy('created_at', 'desc')->get();
         //No posts on this page
         if ($limitsPosts->count() == 0) {
             //Return null
             return null;
         }
         //Return paginator
         return new LengthAwarePaginator($limitsPosts, $postsCount, $numberPerPage, $page, ['path' => current_url()]);
     } catch (Exception $e) {
         //Unexpected error
         return null;
     }
 }
 /**
  * Un-friends two users
  *
  * @param \App\Eloquent\User $user1
  * @param \App\Eloquent\User $user2
  * @return bool
  */
 public function unfriendUsers($user1 = null, $user2 = null)
 {
     //Remove user2 from user1's friends
     $user1->friends()->detach($user2->id);
     //Remove user1 from user2's friends
     $user2->friends()->detach($user1->id);
     //Return results completed
     return true;
 }