title: Order by and Group by with Laravel
body: <p>In my current code I'm using groupBy for a specific column and also I want to order each array by <strong>order_no</strong>. With my current code I get:</p>
  <blockquote>
  <p>&quot;Method Illuminate\Database\Eloquent\Collection::orderBy does not
  exist.&quot;</p>
  </blockquote>
  <pre><code>    $courses = CourseTopic::select([
          'course_topics.id',
          'course_topics.course_id',
          'course_topics.description',
          'course_topics.visible',
          'course_topics.name',
          'course_activities.order_no',
          'course_activities.activity_id',
          'activity_types.table_name'
      ])
      -&gt;where('course_id', $course_id)
      -&gt;leftJoin('course_activities', 'course_activities.course_topic_id', 'course_topics.id')
      -&gt;leftJoin('activity_types', 'activity_types.id', 'course_activities.activity_type_id')
      -&gt;get()
      -&gt;groupBy('id')
      -&gt;orderBy('course_activities.order_no');
  </code></pre>
  <p><a href="https://i.stack.imgur.com/WPckC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WPckC.jpg" alt="enter image description here" /></a></p>