如何在视图中访问集合对象

时间:2014-04-26 12:41:17

标签: laravel-4 eloquent

enter image description here

这是查询

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

我无法访问图片上的关系 谢谢你的回答

1 个答案:

答案 0 :(得分: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