0

After making some queryes i have a collection of array objects. But after orderByDesc the data transform in hole objects, instead of how it was (array of objects), what it happened? Is like the method orderByDesc tranform the collection in another type.

Ex: some logic code, queries...etc in the end

return $total->sortByDesc('date');

After using sortByDesc:

enter image description here

Before to sortByDesc: enter image description here

Now that is in type of objects is giving some issues working with it in my javascript application (angularjs), it not a array of objects how should it be.

1
  • try return $total->sortByDesc('date')->toArray(); Commented Mar 9, 2017 at 1:37

1 Answer 1

3

Try to copy the collection when sorting and use values()

$sorted = $total->sortByDesc('date');
dd($sorted->values());

Same result?

Sign up to request clarification or add additional context in comments.

1 Comment

When you do collection manipulation, it changes the values. That's why you copy to a new variable, and take the variables values(). Don't forget to upvote and mark my answer. Thanks :)

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.