title: Laravel error: Call to a member function first() on string when using Resource::collection
body: <p>I'm creating an backend with multiple stores. Each stores with their own products</p>
  
  <p>I've created a store and a product and am trying to resource the products to all the stores. </p>
  
  <p>When I try add my products to my store in <code>StoreResource.php</code></p>
  
  <p>using:</p>
  
  <pre><code>'products' =&gt; ProductResource::collection($this-&gt;products),
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>Call to a member function first() on string</p>
  </blockquote>
  
  <p>I've looked on line for numerous explanations and tutorials, but get met with the same error</p>
  
  <p><strong>* STORE MODEL *</strong></p>
  
  <pre><code>public function products()
  {
    return $this-&gt;hasMany(Product::class);
  }
  </code></pre>
  
  <p><strong>*STORE CONTROLLER *</strong></p>
  
  <pre><code>public function index()
  {
      return StoreResource::collection(Store::with('products')-&gt;paginate(5));
  }
  </code></pre>
  
  <p><strong><em>STORE Resource</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class StoreResource extends JsonResource
  {
      /**
       * Transform the resource into an array.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
      public function toArray($request)
      {
          return [
           'id' =&gt; $this-&gt;id,
           'name' =&gt; $this-&gt;name,
           'description' =&gt; $this-&gt;description,
           'image' =&gt; $this-&gt;image,
           'created_at' =&gt; (string) $this-&gt;created_at,
           'updated_at' =&gt; (string) $this-&gt;updated_at,
           'products' =&gt; ProductResource::collection($this-&gt;products),
         ];
      }
  }
  </code></pre>
  
  <p><strong>* Product MODEL *</strong></p>
  
  <pre><code>public function stores()
  {
      return $this-&gt;belongsTo(Store::class);
  }
  </code></pre>
  
  <p><strong>*Product CONTROLLER *</strong></p>
  
  <pre><code>public function index()
  {
      return ProductResource::collection(Product::with('stores')-&gt;paginate(5));
  }
  </code></pre>
  
  <p><strong><em>Product Resource</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  
  
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class Purchaseresource extends JsonResource
  {
      /**
       * Transform the resource into an array.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
      public function toArray($request)
      {
        return [
          'id' =&gt; $this-&gt;id,
          'productName' =&gt; $this-&gt;productName,
          'amount' =&gt; $this-&gt;amount,
          'total_product_price' =&gt; $this-&gt;total_product_price,
          'week' =&gt; $this-&gt;week,
          'day' =&gt; $this-&gt;day,
          'month' =&gt; $this-&gt;month,
          'year' =&gt; $this-&gt;year,
          'created_at' =&gt; (string) $this-&gt;created_at,
          'updated_at' =&gt; (string) $this-&gt;updated_at,
        ];
     }
  }
  </code></pre>
  
  <p>What I expect is to get a relation between my store and products so they are displayed as this in the API repsonse</p>
  
  <pre><code> {
      "id": 0, 
      "name": "Store", 
      "image": "image",
      "products": [
          {
              "id": 1,
              "name": "product",
              "price": 7,
              "qty": 100,
              "total": 0
          },
       ]    
  }
  </code></pre>
  
  <p>So the product would become nested in the store.</p>