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!