Laravel change pagination data
<p>My Laravel pagination output is like laravel pagination used to be, but I need to change the data array for each object.
My output is:</p>

<p><a href="https://i.stack.imgur.com/wokI8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wokI8.png" alt="Output"></a></p>

<p>As you can see, the data object has 2 items, which I need to change.</p>

<p>My code is:</p>

<pre><code>$items = $this-&gt;items()
        -&gt;where('position', '=', null)
        -&gt;paginate(15);
</code></pre>

<p>Which returns the user items with pivot table, but I don't like the way the pivot table is shown in the JSON, so I decided to change the items and organize each item with the pivot before the item.</p>

<p>For this purpose, I tried to use <code>foreach</code></p>

<pre><code>foreach ($items-&gt;data as $item)
        {

        }
</code></pre>

<p>which giving my an error, for a reason I don't know:</p>

<pre><code>Undefined property: Illuminate\Pagination\LengthAwarePaginator::$data"
status_code: 500
</code></pre>

<p>Any help?</p>