dqhr76378 2014-09-12 20:20
浏览 25

Laravel加入并显示子类别

I try to build a forum-like query with joins, but without success so far.

What I have so far is:

$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();

In database i have two forums records and one category record, but this query shows two same categories but 2 different forums.

Example:

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] => 
        )

)

Is it even possible to do that with joins?

Best regards!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)