2014-04-26 97 views
0

enter image description here如何訪問集合對象鑑於

這是查詢

$product = Product::with('categories')->take(5)->get(); 

我不能像 感謝訪問關係的答案

+0

哪裏代碼的其餘部分?你是否將'$ product'集合傳遞給視圖?您如何在視圖中訪問它? – ceejayoz

回答

0
// for clarity name this plural as this is a collection too 
$products = Product::with('categories')->take(5)->get(); 

// then in your view: 
@foreach ($products as $product) 
    $product->categories; // accessible like that