我在对标签页进行分页时遇到问题,该页列出了与标签关联的所有产品(多对多)。标签页在 slug 上找到。我有与产品相关评论中以最高平均评级订购的标签相关的产品列表。不幸的是,我似乎无法让分页工作。有谁知道我会如何从下面的代码中做到这一点
表:
products: id, name, price, approved
tags: id, name, slug
-products_tag: id, product_id, tag_id
reviews: id, comment, rating, product_id
当前代码:
public function show($slug)
{
//
$tag = Tag::with(['products' => function ($query) {
return $query->where('approved', '=', 1)
->leftJoin('reviews', 'reviews.products_id', '=', 'products.id')
->select('products.*', DB::raw('AVG(rating) as ratings_average' ))
->groupBy('id')
->orderBy('ratings_average', 'DESC');}])->where('slug', $slug)->first();
return view('tags.show')->withTag($tag);
}