Here is my code:
return ApiResponse::Json(200, '', ['categories' => $categories], 200);
And here is a screenshot of the result:

Now, I need to unset items inside categories collection based on a specific logic. So I wrote this loop:
foreach ($categories as $key => $category) {
if ($category->BusinessSubCategory->isEmpty())
unset($categories[0]);
}
return ApiResponse::Json(200, '', ['categories' => $categories], 200);
And here is my new result: (which is casted to an object)

Well .. What's wrong? How can I keep the old structure after unseting some items?