Header Ads

Header ADS

Laravel average review and review count display

  public function viewProduct($product_slug)

    {
       
            // Retrieve the product by its slug along with the review count
            $product = Product::where('slug', $product_slug)
                              ->withCount('reviews') // eager load review count
                              ->first();

            // Fetch review count and average rating for the product
            $productReviewsCount = ProductReview::where('product_id', $product->id)->count();
            $productRatingAverage = ProductReview::where('product_id', $product->id)->avg('star_count');

        return view('front.product.product-details', compact('product','productReviewsCount','productRatingAverage'));
    } //end Method

No comments

Theme images by fpm. Powered by Blogger.