$shopId])->sum('service_comment'); $commentCount = GoodsComment::where(['shop_id'=>$shopId])->count(); $shopGoodsComment = 0; if($commentCount){ $shopGoodsComment = round($shopAllComment/$commentCount,2); } Shop::update(['good_comment'=>$shopGoodsComment],['id'=>$shopId]); return true; } }