如何获得餐厅的平均价格?查询时不执行循环
餐厅有很多菜单。菜单有很多费率。
在样板餐厅
public function menus()
{
return $this->hasMany('App\Models\Menu', 'fk_restaurant');
}
在模型菜单中
public function reviews()
{
return $this->hasMany('App\Models\Rate', 'fk_service');
}
RestaurantController 中的代码
$mostRatedRestaurants = Restaurant::where('status', 1)->with('menus')->get();
在添加问题之前我正在搜索但是当尝试任何解决方案时出现错误“调用 int 上的成员函数 addEagerConstraints()”
谢谢,高级。
慕姐8265434
汪汪一只猫