title: "Attempt to read property \"id\" on string" laravel api
body: <p>ProductController.php</p>
  <pre><code>class ProductController extends Controller
  {
      public function index(Request $request)
      {
          $limit = $request-&gt;has('limit') ? $request-&gt;get('limit') : 10;
          $offset = $request-&gt;has('offset') ? $request-&gt;get('offset') : 0;
  
          $products = Product::offset($offset)-&gt;limit($limit)-&gt;get();
          return new ProductResource($products);
      }
      //Search Products
      public function search($name, Request $request)
      {
          $limit = $request-&gt;has('limit') ? $request-&gt;get('limit') : 10;
          $offset = $request-&gt;has('offset') ? $request-&gt;get('offset') : 0;
  
          $products = Product::where('name', 'like', '%' . $name . '%')
              -&gt;offset($offset)-&gt;limit($limit)-&gt;get();
          return new ProductResource($products);
      }
  
  }
  </code></pre>
  <p>ProductResource.php</p>
  <pre><code>class ProductResource extends JsonResource
  {
   
      public function toArray($request)
      {
  
          foreach ($request-&gt;all() as $product) {
              $response = [
                  'id' =&gt; &quot;p&quot; . $product-&gt;id,
                  'name' =&gt; $product-&gt;name,
                  'slug' =&gt; $product-&gt;slug,
                  'regular_price' =&gt; $product-&gt;regular_price,
                  'sale_price' =&gt; $product-&gt;sale_price,
                  'SKU' =&gt; $product-&gt;SKU,
                  'stock_status' =&gt; $product-&gt;stock_status,
                  'quantity' =&gt; &quot;p&quot; . &quot;$product-&gt;quantity&quot;,
                  'image' =&gt; $product-&gt;url,
                  'images' =&gt; $product-&gt;url,
                  'category_id' =&gt; $product-&gt;category_id,
  
              ];
              $responses[] = $response;
  
          }
          return response($responses, 201);
  
      }
  }
  </code></pre>
  <p>This is my get route from api (<a href="http://127.0.0.1:8000/api/products?limit=5&amp;offset=0" rel="nofollow noreferrer">http://127.0.0.1:8000/api/products?limit=5&amp;offset=0</a>)
  when send,
  &quot;message&quot;: &quot;Attempt to read property &quot;id&quot; on string&quot;,
  &quot;file&quot;: &quot;/Applications/XAMPP/xamppfiles/htdocs/DNI_E_commerce/app/Http/Resources/ProductResource.php&quot;,
  &quot;line&quot;: 20,</p>