Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bacordioroger's avatar

Laravel Resource for merged collections

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

0 likes
2 replies
bacordioroger's avatar

Hi, yes I'm using it. But how can I map it in the API Resources?

Please or to participate in this conversation.