多级关系查询构建器

时间:2018-11-16 09:25:08

标签: php laravel laravel-query-builder

我有4张桌子

Announcements_reviews

用户

公告

行李公告

Announcements_reviews 公告用户

有关系

公告行李公告

有关系

如何直接从 Announcements_reviews表

中获取 Bagage_Announcements 字段

我这样做了,但是没用

$bagage=DB::table('announcements_reviews_comments')
->join('users','users.id','announcements_reviews_comments.user_id')
->join('announcements','announcements.id','announcements_reviews_comments.id_announcement')
->join('bagage_announcements','bagage_announcements.id_announcement','annoucements.id')
->select(DB::raw('id_announcement as Announcement'),DB::raw('avg(note) as Note'),DB::raw('users.email'),DB::raw('announcements.type'))
->groupBy(DB::raw('id_announcement') )
->get();

0 个答案:

没有答案