2017-07-18 2 views
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']); 
} 
+0

Ich weiß nicht Ihre Frage, was willst du bekommen? –

+0

Ich habe das behoben. $ shoppingCart = ShoppingCart :: where ('Schlüssel', $ Schlüssel) -> mit ('shoppingCartItems', 'shoppingCartItems.product', 'shoppingCartItems.product.images') -> first(); –

+0

so wurde dieses Problem behoben? –

Antwort

0

ich so fixiert.

$shoppingCart = ShoppingCart::where('key' ,$key)->with('shoppingCartItems', 'shoppingCartItems.product', 'shoppingCartItems.product.images')->first(); 
Verwandte Themen