我尝试使用连接构建类似论坛的查询,但到目前为止还没有成功。
到目前为止我所拥有的是:
$categories = DB::table('categories')
->join('forums', function($forums) {
$forums->on('categories.id', '=', 'forums.categoryid');
})
->leftJoin('topics', function($topics) {
$topics->on('forums.id', '=', 'topics.forumid');
})
->get();
在数据库中,我有两个论坛记录和一个类别记录,但此查询显示两个相同的类别,但有两个不同的论坛。
示例:
Array
(
[0] => stdClass Object
(
[id] => 1
[title] => Üldine
[description] => Kõik üldine siia
[categoryid] => 1
[forum_name] => Informatsioon
[forum_description] => Kõik seoses kommuuniga...
[forumid] => 1
[topic_name] => Test Topic 1
[topic_description] => Test topic description
)
[1] => stdClass Object
(
[id] =>
[title] => Üldine
[description] => Kõik üldine siia
[categoryid] => 1
[forum_name] => Informatsioon 2
[forum_description] => Info 2 test
[forumid] =>
[topic_name] =>
[topic_description] =>
)
)
甚至可以用连接来做到这一点吗?
祝你好运!