我正在重写一些 PHP/MySQL 来与 Laravel 一起使用。我想做的一件事是使数据库查询更加简洁使用 Fluent 查询生成器 http://laravel.com/docs/database/fluent但我有点迷失:
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
This queries a phpbb forum and gets posts:
我如何重写它以使用 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'
));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)