7 months ago

How to sort a groupBy?

Posted 7 months ago by Ibe

Hi there, I am having a problem to sort a groupBy.. So this code works perfectly, but the problem is my years are displaying in a random order.. So what I would love is to see the most recent year on top and the others following. Can someone help me pls?


  public function getCommemorative(){
    $commemoratives = Commemorative::orderBy('month', 'desc')->paginate(15)->groupBy('year');

    return view('pages/commemorative')->withCommemoratives($commemoratives);


@foreach ($commemoratives as $year => $commemoratives)

    <h1>{{ $year }}</h1>

    @foreach ($commemoratives->where('jointly_id', '') as $commemorative)

        <div class="">
          <img src="/images/commemorative-coins/{{$commemorative->image}}" class="" alt="">




Please sign in or create an account to participate in this conversation.