我正在尝试结合 4 个模型来获得摘要报告。这些是我的桌子。
user
-id
-name
-country_id
country
-id
-name
invoice
-id
-user_id
-type_id
type
-id
-name
我想根据国家/地区计算每种类型的发票详细信息。就是这样。
country | type_name_1 | type_name_2 | type_name_2
America | 10 | 2 | 4
Canada | 62 | 0 | 35
China | 23 | 9 | 5
我尝试了以下查询,但它并没有完全给出我想要的答案。
\App\Invoice::all()->groupBy(function($s){
return $s->user->country->name;
})->groupBy(function($s){
return $s->type->count();
})
错误:带有消息“此集合实例上不存在属性 [类型]”的异常。
有人可以在这里给我指点吗?