title: Add a custom item to eloquent collection
body: <p>I am using Laravel 7.</p>
  <p>I have <code>Category</code> model. I sent categories as API with laravel resources. But now I want to add &quot;all&quot; value to categories.</p>
  <p>Controller:</p>
  <pre><code>'categories' =&gt; CategoryResource::collection(Category::all()-&gt;push([
        'id' =&gt; 0,
        'name' =&gt; &quot;All&quot;,
        'subcategories' =&gt; []
   ]))
  </code></pre>
  <p>Resource:</p>
  <pre><code>public function toArray($request)
  {
       return [
            'id' =&gt; $this-&gt;id,
            'name' =&gt; $this-&gt;name,
            'subcategories' =&gt; SubcategryResource::collection($this-&gt;subcategories)
       ];
  }
  </code></pre>
  <p>Also, I wanted to add this custom value to the beginning of the collection.</p>
  <p>But I am getting this error:</p>
  <blockquote>
  <p>Trying to get property 'id' of non-object</p>
  </blockquote>
  <p>Please, help me. How can I solve my problem?</p>