title: Getting an API response in single array having different objects
body: <p>I'm getting a response in the data array and then there are different arrays for each object array but I only want a single data array containing all objects. This is my code. First, I'm getting the products and then storing their filtered result in an array and then making that array unique, and then sending this response. I've also tried sending the values directly but still, it has parent and children arrays. Attaching the response picture also.</p>
  <p><a href="https://i.stack.imgur.com/4WoY8.png" rel="nofollow noreferrer">API Response</a></p>
  <p><a href="https://i.stack.imgur.com/4WoY8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4WoY8.png" alt="API response" /></a></p>
  <pre><code>public function categoriesAndProducts(Request $request)
      {
          $marketId = $request-&gt;marketId;
          try {
              $this-&gt;categoryRepository-&gt;pushCriteria(new RequestCriteria($request));
              $this-&gt;categoryRepository-&gt;pushCriteria(new LimitOffsetCriteria($request));
              $this-&gt;categoryRepository-&gt;pushCriteria(new CategoriesOfFieldsCriteria($request));
          } catch (RepositoryException $e) {
              Flash::error($e-&gt;getMessage());
          }
          $products = DB::table('products')-&gt;where('market_id', $marketId)-&gt;groupBy('category_id')-&gt;get();
          //  return $products;
          $arr = [];
          foreach ($products as $product) {
              $arr[] = $this-&gt;categoryRepository-&gt;where('id', $product-&gt;category_id)-&gt;get();
          }
  $values = array_unique($arr, SORT_REGULAR);
  return $this-&gt;sendResponse($values, 'Categories retrieved successfully');
  </code></pre>