Created
November 27, 2019 06:25
-
-
Save aslamdoctor/32edf3f6b6986401b09c0a36a5b7373b to your computer and use it in GitHub Desktop.
Laravel : Maintain Sort order in JSON Response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user = $request->user(); | |
$submissions = $user->submissions; | |
// do these in the end | |
$submissions = $submissions->sortByDesc(function($submission){ | |
return $submission->created_at; | |
}); | |
$submissions = array_values($submissions->toArray()); | |
// Return response | |
return response([ | |
'data' => $submissions, | |
], 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment