Let say my category level is like:
Parent
- child one
- child two
- child two (one)
Now I am visiting Parent
page. but i want to get all products from all levels and not only parent.
parent
child one
child two
& child two(one)
? parent
page? this is what i have currently and it only shows products under parent
public function totalcategoriessubs($catslug) {
$categories = Category::where('slug','=',$catslug)->with('childs')->paginate(12);
$products = Product::whereHas('category', function($q) use($catslug){
$q->where('slug',$catslug);
})->paginate(12);
return view('front.categoriessubs', compact('products', 'categories'));
}
I have changed my function and added $category
to it so now is like:
public function totalcategoriessubs($catslug) {
//changed
$category = Category::where('slug','=',$catslug)->with('childs')->first();
//testing this
$products = Product::whereHas('category', function($q) use ($catslug,$category)
{
$q->where(function($q) use ($catslug,$category) {
$q->where('slug',$catslug)->orWhere('category_id',$category->id);
});
})->orderBy('created_at', 'DESC')->paginate(10);
//end testing
return view('front.categoriessubs', compact('products', 'category'));
}
with this i can get product
list of
Parent
- child one
- child two
but still can't get products of child two (one)
any idea?
Category::with(['childsOne', 'childsTwo' => function($query){
$query->with('ChildsTwoChilds');
])->where('slug', $catSlug)->paginate(12)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.