我有這樣的查看:Laravel 5.1 - 嵌套循環 - 刀片模板
..
...
<div class="section group">
@foreach ($product as $item)
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">{!! $item->name !!}</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ {!! $item->price !!} </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
@endforeach
</div>
...
..
這對控制器:
..
...
public function index(){
$product = product::paginate(8);
return view('shop.index', compact('product'));
}
...
..
我想展現給數據我將控制器分成兩部分,輸出如下:
<div class="section group">
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 01</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 01 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 02</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 02 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 03</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 03 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 04</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 04 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div class="section group">
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 05</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 05 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 06</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 06 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 07</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 07 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
<div class="grid_1_of_4 images_1_of_4">
<h4><a href="#">item 08</a></h4>
<div class="price-details">
<div class="price-number">
<p><span class="price">$ price 08 </span></p>
</div>
<div class="add-cart">
<h4><a href="#">More Info</a></h4>
</div>
<div class="clear"></div>
</div>
</div>
</div>
我認爲它應該使用嵌套循環,但我不知道如何在laravel中編寫它。
任何人有任何想法應該如何?
您的'print_r($ product');退出;'返回之前? – aldrin27