title: output category with child categories and posts and pagination
body: <p>I want to get category with all children subcategories and posts where id = category_id.
  Posts should be paginated.
  In category model I have 2 relations.</p>
  <pre><code>    public function children()    {
          return $this-&gt;hasMany(self::class, 'parent_id');
      }
  
      public function posts() { 
          return $this-&gt;hasMany(Post::class, 'category_id'); 
      }
  </code></pre>
  <p>In controller I have this function</p>
  <pre><code>    public function getCategoryWithPaginatedPosts($slug, $perPage = null)
      {
          $columns = ['id', 'parent_id', 'title', 'slug', 'description', 'image'];
          $postsColumns = ['category_id','title','text'];
  
          $result = Category::whereSlug($slug)
              -&gt;select($columns)
              -&gt;with('children')
              -&gt;with(['items' =&gt; function ($q) use ($postColumns) { 
                  $q-&gt;wherePublished(true)
                    -&gt;select($postColumns)
                    -&gt;orderBy('id', 'ASC')
                    -&gt;paginate(); 
              }]) 
              -&gt;first();
       }
  </code></pre>
  <p>Pagination doesn't work.
  I just see that number of items is equal to $perPage parameter (and I have more items), but I don't see paginator inside <strong>dd($result-&gt;items)</strong></p>
  <p>It works like that, though I believe it is not the best way to do that.
  So I can do it in few steps.
  In first step I retrieve all data from DB and convert models to array, because I don't need models on webpage and I suppose it works faster like that. I would use <strong>-&gt;toBase()</strong> if it could take mutators and relations from the model.
  Second step I convert array into stdClass, because it is more comfortable in blade to work with object rather than with array.
  Third step is to paginate items with <strong>mypaginate</strong> function (manual paginator in AppService Provider).</p>
  <pre><code>    public function getCategoryWithPaginatedPosts($slug, $perPage = null)
      {
          $columns = ['id', 'parent_id', 'title', 'slug', 'description', 'image'];
          $postsColumns = ['category_id','title','text'];
  
          $result = Category::whereSlug($slug)
              -&gt;select($columns)
              -&gt;with('children')
              -&gt;with(['items' =&gt; function ($q) use ($postColumns) { 
                  $q-&gt;wherePublished(true)
                    -&gt;select($postColumns)
                    -&gt;orderBy('id', 'ASC');
              }]) 
              -&gt;first()
              -&gt;toArray();
  
          $result = Arr::arrayToObject($result);
          $result-&gt;items = collect($result-&gt;items)-&gt;mypaginate($perPage);
  
          return $result;
  
       }
  </code></pre>