title: Error: Call to a member function paginate() on a non-object
body: <p>I'm trying to transform some data retrieved as an object from an Eloquent model, and then use Laravel's paginate functionality too. However, when I cast the data to an array in order to transform it, I can't then use the paginate method.</p>
  
  <pre><code>$postsPerPage = 10;
  
  $posts = Post::where('published', '=', true)-&gt;get();
  
  $posts = Helpers::transform_posts($posts-&gt;toArray());
  
  // $posts = Helpers::transform_posts($posts-&gt;toArray())-&gt;paginate($postsPerPage);
  // doesn't work because $posts has been cast to an array
  // error: Call to a member function paginate() on a non-object
  
  return View::make('blog.index', ['posts' =&gt; $posts]);
  </code></pre>
  
  <p>Class Helpers:</p>
  
  <pre><code>public static function transform_post(array $post)
  {
      $publishedDate = \Carbon\Carbon::createFromTimeStamp(strtotime($post['published_date']))-&gt;diffForHumans();
  
      return [
          'id' =&gt; $post['id'],
          'title' =&gt; $post['title'],
          'slug' =&gt; $post['slug'],
          'subtitle' =&gt; $post['subtitle'],
          'body' =&gt; $post['body'],
          'published' =&gt; (bool)$post['published'],
          'published_date' =&gt; $post['published_date'],
          'published_date_for_humans' =&gt; $publishedDate
      ];
  }
  
  public static function transform_posts(array $posts)
  {
      foreach ($posts as &amp;$array) {
          $array = Helpers::transform_post($array);
      }
      return $posts;
  }
  </code></pre>
  
  <p>How can I do this without casting to an array, so that I can still use the paginate method on the data?</p>
  
  <p>Edit: This is now solved with:</p>
  
  <pre><code>    $posts = Post::where('published', '=', true)-&gt;get()-&gt;toArray();
  
      $posts = Helpers::transform_posts($posts);
  
      $posts = Paginator::make($posts, 0 , $postsPerPage);
  
      return View::make('blog.index', ['posts' =&gt; $posts]);
  </code></pre>