当我试图使用withCount检索记录,同时又想以不同的名称返回一个字段时,我在laravel中遇到了一个问题。如果我删除了getCount,查询将正确返回字段,但是当我添加withCount时,它将忽略语句中的AS子句。Maker::where('type_id', $request->type_id)->get(['maker_name AS label', 'id A
product_category_id' );现在每个类别都有一些类似于(cat-1 has 3 products, cat-2 has 7 products, cat-3 has 5 products)的产品我需要一个Eloquent query,这将得到4个类别,按计数的产品在每个类别。
为了快递。