【发布时间】:2019-05-09 13:26:48
【问题描述】:
我有一个问题..在我的程序中,我需要有一个 User 的集合,这是另一个集合,其中包含用户参与的所有项目以及他在每个项目中工作的 hours 的数量。
我有 3 个表来解决这个问题:
-
users桌子,很简单。 -
projects表。 -
time_entries,与user_id和project_id。
一个project可以有多个time_entries和user。
我已经测试过了,但它不起作用:
$users = User::join('time_entries', 'users.id', '=', 'time_entries.user_id')
->whereBetween('spent_on', [($request->input('debut')), ($request->input('fin'))])
->join('projects', 'time_entries.project_id', '=', 'projects.id')
->selectRaw('user_id , project_id, sum(hours) as sum')
->get();
【问题讨论】:
标签: php laravel collections eloquent