{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/26666","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/26666/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/26666/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/26666/events","html_url":"https://github.com/laravel/framework/pull/26666","id":385691776,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0NjAyODM5","number":26666,"title":"[5.7] add sortByIds method to eloquent collections","user":{"login":"apollopy","id":2421282,"node_id":"MDQ6VXNlcjI0MjEyODI=","avatar_url":"https://avatars0.githubusercontent.com/u/2421282?v=4","gravatar_id":"","url":"https://api.github.com/users/apollopy","html_url":"https://github.com/apollopy","followers_url":"https://api.github.com/users/apollopy/followers","following_url":"https://api.github.com/users/apollopy/following{/other_user}","gists_url":"https://api.github.com/users/apollopy/gists{/gist_id}","starred_url":"https://api.github.com/users/apollopy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollopy/subscriptions","organizations_url":"https://api.github.com/users/apollopy/orgs","repos_url":"https://api.github.com/users/apollopy/repos","events_url":"https://api.github.com/users/apollopy/events{/privacy}","received_events_url":"https://api.github.com/users/apollopy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-11-29T11:31:29Z","updated_at":"2018-11-29T14:38:29Z","closed_at":"2018-11-29T13:00:59Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/26666","html_url":"https://github.com/laravel/framework/pull/26666","diff_url":"https://github.com/laravel/framework/pull/26666.diff","patch_url":"https://github.com/laravel/framework/pull/26666.patch"},"body":"This is a feature that is often needed in everyday coding.\r\n\r\nWe often get Eloquent ids from Redis or Elasticsearch, such as leaderboard,. At this point, we want to get the collection set with the same ID order.\r\n\r\n```php\r\n// id from Redis or Elasticsearch ...\r\n$ids = [2, 1, 3]; \r\n\r\n// the data returned by mysql, sorted by id asc: [['id' => 1], ['id' => 2], ['id' => 3]]\r\n$posts = Post::find($ids); \r\n\r\n// reorder by $ids  [1 => ['id' => 2], 0 => ['id' => 1], 2 => ['id' => 3]]\r\n$posts = $posts->sortByIds($ids);\r\n```"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/442856444","html_url":"https://github.com/laravel/framework/pull/26666#issuecomment-442856444","issue_url":"https://api.github.com/repos/laravel/framework/issues/26666","id":442856444,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Mjg1NjQ0NA==","user":{"login":"apollopy","id":2421282,"node_id":"MDQ6VXNlcjI0MjEyODI=","avatar_url":"https://avatars0.githubusercontent.com/u/2421282?v=4","gravatar_id":"","url":"https://api.github.com/users/apollopy","html_url":"https://github.com/apollopy","followers_url":"https://api.github.com/users/apollopy/followers","following_url":"https://api.github.com/users/apollopy/following{/other_user}","gists_url":"https://api.github.com/users/apollopy/gists{/gist_id}","starred_url":"https://api.github.com/users/apollopy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apollopy/subscriptions","organizations_url":"https://api.github.com/users/apollopy/orgs","repos_url":"https://api.github.com/users/apollopy/repos","events_url":"https://api.github.com/users/apollopy/events{/privacy}","received_events_url":"https://api.github.com/users/apollopy/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T14:38:29Z","updated_at":"2018-11-29T14:38:29Z","author_association":"CONTRIBUTOR","body":"> Why not make it more generic and allow this for any type of attribute?\r\n> Would be nice to be able to do this with any attribute and not just the keys!\r\n> \r\n> Also if my quick glance is right then his seems to throw an `undefined index` notice when the `$ids` don't match the present keys, and thus you would need to know exactly what your query returns to sort properly?\r\n\r\nI fixed the undefined error. Put undefined ids at the end.\r\n\r\nI don't support any attributes because they are not common and sort is more flexible.\r\n\r\n"}}
{"actor":{"display_login":"apollopy"}}