0
Ich entwickle Webshop. Ich habe die folgenden Beziehungen in meinem Modell.Erhalte Daten aus der Beziehungstabelle
shoppingCart -> hasMany -> shoppingCartItem
shoppingCartItem -> belongTo -> shoppingCart
Ich habe in meiner Controller-Funktion die product_id
$product = Product::find($request->get('product_id'))->first();
in der Produkttabelle Ich habe Beziehung mit dem Bild zu bekommen. Ich speichere das Bild in einer anderen Tabelle, die nur product_id und image_id hat.
Nun ist meine Frage kann ich
public function getCart(Request $request)
{
// get the shoppingCart
$shoppingCart = $this->loadShoppingCart($request->get('key'));
$carts = [
'amount' => $shoppingCart->total_products,
'price'=>$shoppingCart->total_price
];
// get theimage of the product
$productImage = Image::with('image_id', $request->get('image_id'));
return response()->json(['carts','productImage']);
}
Ich weiß nicht Ihre Frage, was willst du bekommen? –
Ich habe das behoben. $ shoppingCart = ShoppingCart :: where ('Schlüssel', $ Schlüssel) -> mit ('shoppingCartItems', 'shoppingCartItems.product', 'shoppingCartItems.product.images') -> first(); –
so wurde dieses Problem behoben? –