I have tables - products and categories with a pivot table. What i need to do is to display the categories on view in a tab and get the respective products.
// Product.php
public function categories(){
return $this->belongsToMany('App\Models\Category');
}
// Category.php
public function products(){
return $this->belongsToMany('App\Product');
}
// IndexController.php
$products = Product::where('status', StatusConstant::PT_ACTIVE)
->with(['joindraw' => function ($query){
$query->where('user_id', $this->user->id);
}])->get();
return view('store.index', ['products' => $products, 'category' => $category]);
and I'm expecting some output like this:
<div class="row">
<div class="col s12">
<ul class="tabs">
<li class="tab"><a class="" href="#tabs1">Category 1</a></li>
<li class="tab"><a class="active" href="#tabs2">Category 2</a></li>
<li class="tab"><a class="" href="#tabs3">Category 3</a></li>
</ul>
</div>
<div id="tabs1" class="col s12">
<div class="contents-tabs">
<div class="table-contents default-table">
//Products in category id 1...
May i know how can i do the filter on blade?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire