0

I want to sort data that is coming from Api resource on the basis of their rating that is coming from the resource. I have been working on the SortByDesc method but it's not giving proper results.

public function reviewlist()
{
    $post = Post::all();
    $list = RatingResource::collection($post);
    
    return  $list->sortByDesc('Rating');
  }

1 Answer 1

2

Got an answer that you have to use this method for applying sort on resource data.

public function reviewlist()
{
    $post = Post::all();
    $list = RatingResource::collection($post);
    
    $statisticCollection = collect($list);

    $sorted = $statisticCollection->sortByDesc('Rating');

    return $sorted->values()->all();
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.