我想要检索同一个表中存储的4种不同类型的产品,并在一个视图中显示它 每个产品的每个类别 Look to this image
//// ******************控制器代码
<?php
namespace App\Http\Controllers;
use App\Produit;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('index');
// carrelage
$indexcarrelage = Produit::where('page',13)->get();
return view('index',compact('indexcarrelage'));
//cuisine
$indexcuisine = Produit::where('page',9)->get();
return view('index',compact('indexcuisine'));
//salle de bain
$indexsalle = Produit::where('page',1)->get();
return view('index',compact('indexsalle'));
//meuble
$indexmeuble = Produit::where('page',2)->get();
return view('index',compact('indexmeuble'));
}
}
////// ******************视图代码
@foreach( $indexcarrelage as $carre)
<div class="col-md-3 product-men">
<div class="men-pro-item simpleCart_shelfItem">
<div class="men-thumb-item">
<img src="{{'images/'.$carre->image}}" alt="image" class="pro-image-front">
<img src="{{'images/'.$carre->image}}" alt="" class="pro-image-back">
<div class="men-cart-pro">
<div class="inner-men-cart-pro">
<a href="{{url('product_details',$carre->id)}}" class="link-product-add-cart">Afficher Produit</a>
</div>
</div>
<span class="product-new-top">nouveaux</span>
</div>
<div class="item-info-product ">
<h4><a href="{{url('product_details',$carre->id)}}">{{$carre->nom}}</a></h4>
</div>
</div>
</div>
@endforeach
//另一个foreach来看下一个产品
@foreach( $indexcuisineas $cuis)
<div class="col-md-3 product-men">
<div class="men-pro-item simpleCart_shelfItem">
<div class="men-thumb-item">
<img src="{{'images/'.$cuis->image}}" alt="image" class="pro-image-front">
<img src="{{'images/'.$cuis->image}}" alt="" class="pro-image-back">
<div class="men-cart-pro">
<div class="inner-men-cart-pro">
<a href="{{url('product_details',$cuis->id)}}" class="link-product-add-cart">Afficher Produit</a>
</div>
</div>
<span class="product-new-top">nouveaux</span>
</div>
<div class="item-info-product ">
<h4><a href="{{url('product_details',$cuis->id)}}">{{$carre->nom}}</a></h4>
</div>
</div>
</div>
@endforeach
并继续使用其他产品 但这对我来说并不适合我,而且我是laravel的新人
答案 0 :(得分:0)
public function index()
{
$indexcarrelage = Produit::where('page',13)->get();
$indexcuisine = Produit::where('page',9)->get();
$indexsalle = Produit::where('page',1)->get();
$indexmeuble = Produit::where('page',2)->get();
return view('index', compact(
'indexcarrelage', 'indexcuisine', 'indexsalle', 'indexmeuble'
));
}
这会将所有这些变量传递给你的观点。