Laravel new threads to appear before bumped threads
<p>I have a forum thread table, that are linked to a comments table</p>

<p>I would like to order my query by their latest comment, and a new thread to appear before that</p>

<p>At the moment, new threads are appearing last</p>

<p>Ideally I need new threads with no comments to appear above them ones and not order after ones with comments? If that makes sense</p>

<p>This picture should explain</p>

<p><a href="https://i.stack.imgur.com/0VeW4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0VeW4.png" alt="enter image description here"></a></p>

<p>The order should be:</p>

<ul>
<li>Fifth Thread (because created last)</li>
<li>Third Thread (should be 2nd because it has a comment before fifth thread was made)</li>
<li>FourthThread</li>
<li>Second Thread</li>
<li>First Thread</li>
</ul>

<p>Here is my Query</p>

<pre><code>public function getThreads($limit = 30)
{
    return ForumThread::select(DB::raw('forum_threads.*, count(*) as count'))
        -&gt;where('cat_id', $this-&gt;id)
        -&gt;where('published', 1)
        -&gt;join('comments', 'comments.thread_id', '=', 'forum_threads.id', 'left outer')
        -&gt;orderBy('pinned', '1')
        -&gt;orderBy('count', 'desc')
        -&gt;orderBy('comments.created_at', 'desc')
        -&gt;groupBy('forum_threads.id')
        -&gt;paginate($limit);
}
</code></pre>

<p>have tried to explain the best I can</p>