This commit is contained in:
Mekan1206
2025-12-23 19:08:58 +05:00
parent ba9402afb0
commit 9f27fe260e

View File

@@ -31,8 +31,7 @@ class CartController extends Controller
} }
}); });
return response()->rest( $data = $cartItems->map(fn ($cartItem) => [
$cartItems->map(fn ($cartItem) => [
'id' => $cartItem->id, 'id' => $cartItem->id,
'user_id' => $cartItem->user_id, 'user_id' => $cartItem->user_id,
'product_id' => $cartItem->product_id, 'product_id' => $cartItem->product_id,
@@ -40,7 +39,18 @@ class CartController extends Controller
'created_at' => $cartItem->created_at, 'created_at' => $cartItem->created_at,
'updated_at' => $cartItem->updated_at, 'updated_at' => $cartItem->updated_at,
'product' => new ProductResource($cartItem->product), 'product' => new ProductResource($cartItem->product),
]) ])->groupBy(function (array $cartItem) {
if (isset($cartItem['product']) && $cartItem['product']->channels->count() > 0) {
return $cartItem['product']->channels[0]->slug;
}
return 'default';
});
return response()->rest(
$data,
code: 200,
message: 'Cart items'
); );
} }