I tried to sort a different kind of status in a model and paginate them in one collection. Is there a way to do this? The sorting will be overridden when I place the sorting condition after the union method.
->with(['user']) "eloquent relation"
->withPaidAt() "scope in lesson to check if lessons is paid"
$lessons = new Lesson();
$upcomingLessons = $lessons
->with(['user'])
->withPaidAt()
->whereNull('online_starts_at')
->orderBy('start_at');
$availableLessons = $lessons
->with(['user'])
->withPaidAt()
->whereNotNull('online_starts_at')
->where('visibility', 'public')
->orderBy('online_starts_at')
->union($upcomingLessons)
->paginate(10);
return $availableLessons;
Already checked this Sorting UNION queries with Laravel 4.1 where
$query1->orderBy('foo desc');
$query2->orderBy('foo desc');
$query1->union($query2);
is not working.