title: Order By before Group By using Eloquent (Laravel)
body: <p>I have a "messages" table with the following columns</p>
  
  <pre><code>CREATE TABLE `messages` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `fromId` int(11) NOT NULL,
    `toId` int(11) NOT NULL,
    `message` text NOT NULL,
    `status` int(11) NOT NULL,
    `device` varchar(100) NOT NULL,
    `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>I'm trying to get all messages where 'toId' = $id and grouping by fromId. The problem is that the "message" shown on the results is the first ones, not the latest ones. I tried ordering by createdAt but it's not working.</p>
  
  <p>How can I order by "createdAt" prior to querying and grouping the results? I want to do this in the laravel way using Eloquent.</p>
  
  <p>My query:</p>
  
  <pre><code>$chats = Message::with('sender','recipient')
          -&gt;where('toId',$id)
          -&gt;orderBy('createdAt')
          -&gt;groupBy('fromId')
          -&gt;paginate(10)
  </code></pre>