Level 11
Easiest way would be to use Eloquent API Resources.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I have this codes:
public function centerCategories(){
$inventories = CategoriesController::getInventory();
$categories = CategoriesController::getSubCategoriesDetails();
$bookings = CategoriesController::getBookings();
$all = collect();
$all->put('inventories', $inventories);
$all->put('categories', $categories);
$all->put('bookings', $bookings);
return InventoryResource::collection($all);
}
public function getInventory(){
$inventory = Inventory::with('getInventoryDetails')->get();
return $inventory;
}
public function getSubCategoriesDetails(){
$sub_category = Sub_Category::with('getSubCategoryDetails')->get();
return $sub_category;
}
public function getBookings(){
$booking = Booking::with('getBookingDetails.getBookingStatus')
->withCount(['getBookingDetails'])->get();
return $booking;
}
How can I map the resource json output thanks
Please or to participate in this conversation.