products->list( filters: new ProductFilters(collectionId: $collection->id), perPage: $perPage, page: $page, ); $products = new LengthAwarePaginator( items: collect($result['data'])->map(fn (array $product) => [ 'name' => $product['name'], 'price' => $product['price'], 'image' => $product['media'][0]['url'] ?? null, 'href' => route('product.show', ['product' => $product['id']]), ]), total: $result['meta']['total'], perPage: $result['meta']['per_page'], currentPage: $result['meta']['current_page'], options: [ 'path' => request()->url(), 'query' => request()->query(), ], ); return view('category.show', [ 'collection' => $collection, 'products' => $products, ]); } }