如何在雄辩的laravel中获得嵌套数组中的总和?

How can i get sum of all results of ratings on reviews array in eloquent laravel?

I've tried this way:

PublicController.php

public function products()
{
    $products = Product::select('id', 'name', 'slug', 'image', 'new', 'offer', 'featured', 'cash_price', 'special_price')
        ->where('status', true)
        ->withCount(['reviews'])
        ->with(['reviews' => function($query){
            $query->select('product_id', 'rating');
            $query->sum('rating'); //<-- dont show anything
        }])
        ->get();
    return response()->json($products, 200);
}

and my result json output is:

[
  {
    "id": 1,
    "name": "Peggie Rodriguez",
    "slug": "peggie-rodriguez",
    "image": "https://lorempixel.com/200/200/?43622",
    "new": 1,
    "offer": 1,
    "featured": "Exercitationem eum praesentium soluta placeat. Ut praesentium non dolorem a et libero. Optio corporis est assumenda aut.",
    "cash_price": 80464,
    "special_price": 10598,
    "reviews_count": 3,
    "reviews": [
      {
        "product_id": 1,
        "rating": 1
      },
      {
        "product_id": 1,
        "rating": 2
      },
      {
        "product_id": 1,
        "rating": 5
      }
    ]
  },
]

My expected output is the sum of all rating values.