我正在使用 Laravel:Livewire 星级组件。我想以星级显示总评分

I'm using Laravel:Livewire star rating Components. I want to show total ratings in stars

评分模块运行良好,也显示了评分数量,但我想以星级显示总评分,但我不知道如何在 blade 视图中写入。

Livewire/ProductRating.php

public $rating;
    public $comment;
    public $currentId;
    public $product;
    public $hideForm;

    protected $rules = [
        'rating' => ['required', 'in:1,2,3,4,5'],
        'comment' => 'required',

    ];

    public function render()
    {
        $comments = Rating::where('product_id', $this->product->id)->where('status', 1)->with('user')->get();
        return view('livewire.product-ratings', compact('comments'));
    }

    public function mount()
    {
        if (auth()->user()) {
            $rating = Rating::where('user_id', auth()->user()->id)->where('product_id', $this->product->id)->first();
            if (!empty($rating)) {
                $this->rating  = $rating->rating;
                $this->comment = $rating->comment;
                $this->currentId = $rating->id;
            }
        }
        return view('livewire.product-ratings');
    }

假设您的 Rating 模型上有一个名为 rating 的 属性,您可以执行以下操作以获得给定 [=13= 的产品的平均评分]:

$average = Rating::where('product_id', $id)->avg('rating');