Php 使用laravel fluent查询生成器从多个表中选择

Php 使用laravel fluent查询生成器从多个表中选择,php,mysql,laravel,Php,Mysql,Laravel,我正在编写一些PHP/MySQL来与Laravel合作。我想做的一件事是使DB查询更加简洁,但我有点不知所措: SELECT p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster FROM phpbb_topics t, phpbb_posts p, phpbb_users u WHERE t.forum_id = 9 AND p.pos

我正在编写一些PHP/MySQL来与Laravel合作。我想做的一件事是使DB查询更加简洁,但我有点不知所措:

SELECT p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster
FROM phpbb_topics t, phpbb_posts p, phpbb_users u
WHERE t.forum_id = 9
AND p.post_id = t.topic_first_post_id
AND u.user_id = t.topic_poster
ORDER BY t.topic_time
DESC LIMIT 10
这将查询phpbb论坛并获得帖子:


如何使用Fluent Query Builder语法重新编写此代码?

未测试,但这是一个开始

return DB::table('phpbb_topics')
    ->join('phpbb_posts', 'phpbb_topics.topic_first_post_id', '=', 'phpbb_posts.post_id')
    ->join('phpbb_users', 'phpbb_topics.topic_poster', '=', 'phpbb_users.user_id')
    ->order_by('topic_time', 'desc')
    ->take(10)
    ->get(array(
        'post_text',
        'bbcode_uid',
        'username',
        'forum_id',
        'topic_title',
        'topic_time',
        'topic_id',
        'topic_poster'
    ));

下面有一个类似的选项(在5.3中测试)->get(数组('phpbb_主题。*','username','phpbb_posts.post_text')这个选项解决了我的问题。如何将这个答案链接到我的问题?编辑:我得到了itUse distinct(),否则,它将根据表计数给出一个重复数据
return DB::table(DB::raw('phpbb_topics t, phpbb_posts p, phpbb_users u')) 
->select(DB::raw('p.post_text, p.bbcode_uid, u.username, t.forum_id, t.topic_title, t.topic_time, t.topic_id, t.topic_poster'))
->where('phpbb_topics.topic_first_post_id', '=', 'phpbb_posts.post_id')
->where('phpbb_users', 'phpbb_topics.topic_poster', '=', 'phpbb_users.user_id')
->order_by('topic_time', 'desc')->take(10)->get();