Я хочу вычислить среднее значение столбца отношения вложенных морфов.
Функция модели
public function trader_ratings()
{
return $this->morphMany(TraderRatings::class, 'rateable')
->select('rateable_id', 'rateable_type', 'rating')
->avg('rating');
}
Контроллер с отложенной загрузкой
$user = auth('api')->user();
$user_id = $user->id;
$customer_classes = CustomerClassBooking::with([
'trader_class',
'trader_class.trader_ratings',
'vendor',
])
->where('customer_id', $user_id)
->where('status', 'Accepted-paid')
->get();
Не вычисляется avg
, но выдается ошибка.