{"action":"created","comment":{"url":"https://api.github.com/repos/laravel/framework/pulls/comments/25997623","id":25997623,"diff_hunk":"@@ -1464,6 +1471,78 @@ protected function restoreFieldsForCount()\n \t}\n \n \t/**\n+\t * Get the count of the total records for the paginator.\n+\t *\n+\t * @return int\n+\t */\n+\tpublic function getGroupCountForPagination()\n+\t{\n+\t\t$sql = $this->toSql();\n+\t\t$this->backupGroupFieldsForCount();\n+\n+\t\t$this->from = new Expression(\"($sql) aggregator_query\");\n+\t\t$total = $this->count();\n+\n+\t\t$this->restoreGroupFieldsForCount();\n+\n+\t\treturn $total;\n+\t}\n+\n+\t/**\n+\t * Backup some fields for the pagination count.\n+\t *\n+\t * @return void\n+\t */\n+\tprotected function backupGroupFieldsForCount()\n+\t{\n+\t\t$fields = [\n+\t\t\t'from',\n+\t\t\t'joins',\n+\t\t\t'wheres',\n+\t\t\t'groups',\n+\t\t\t'havings',\n+\t\t\t'orders',\n+\t\t\t'limit',\n+\t\t\t'offset',\n+\t\t\t'unions',\n+\t\t];\n+\n+\t\tforeach ($fields as $field)\n+\t\t{\n+\t\t\t$this->backups[$field] = $this->{$field};\n+\n+\t\t\t$this->{$field} = null;\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Restore some fields after the pagination count.\n+\t *\n+\t * @return void\n+\t */\n+\tprotected function restoreGroupFieldsForCount()\n+\t{\n+\t\t$fields = [","path":"src/Illuminate/Database/Query/Builder.php","position":71,"original_position":71,"commit_id":"8f84ee62b3969f04a6cc59bd782afc17f9bce414","original_commit_id":"8f84ee62b3969f04a6cc59bd782afc17f9bce414","user":{"login":"lucasmichot","id":513603,"avatar_url":"https://avatars.githubusercontent.com/u/513603?v=3","gravatar_id":"","url":"https://api.github.com/users/lucasmichot","html_url":"https://github.com/lucasmichot","followers_url":"https://api.github.com/users/lucasmichot/followers","following_url":"https://api.github.com/users/lucasmichot/following{/other_user}","gists_url":"https://api.github.com/users/lucasmichot/gists{/gist_id}","starred_url":"https://api.github.com/users/lucasmichot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucasmichot/subscriptions","organizations_url":"https://api.github.com/users/lucasmichot/orgs","repos_url":"https://api.github.com/users/lucasmichot/repos","events_url":"https://api.github.com/users/lucasmichot/events{/privacy}","received_events_url":"https://api.github.com/users/lucasmichot/received_events","type":"User","site_admin":false},"body":"`$fields` is repeated so this should be probably a class property.","created_at":"2015-03-07T17:20:50Z","updated_at":"2015-03-07T17:20:50Z","html_url":"https://github.com/laravel/framework/pull/7648#discussion_r25997623","pull_request_url":"https://api.github.com/repos/laravel/framework/pulls/7648","_links":{"self":{"href":"https://api.github.com/repos/laravel/framework/pulls/comments/25997623"},"html":{"href":"https://github.com/laravel/framework/pull/7648#discussion_r25997623"},"pull_request":{"href":"https://api.github.com/repos/laravel/framework/pulls/7648"}}},"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/7648","id":30171283,"html_url":"https://github.com/laravel/framework/pull/7648","diff_url":"https://github.com/laravel/framework/pull/7648.diff","patch_url":"https://github.com/laravel/framework/pull/7648.patch","issue_url":"https://api.github.com/repos/laravel/framework/issues/7648","number":7648,"state":"open","locked":false,"title":"[5.0] Correct page count with group by clauses","user":{"login":"derekhamilton","id":272878,"avatar_url":"https://avatars.githubusercontent.com/u/272878?v=3","gravatar_id":"","url":"https://api.github.com/users/derekhamilton","html_url":"https://github.com/derekhamilton","followers_url":"https://api.github.com/users/derekhamilton/followers","following_url":"https://api.github.com/users/derekhamilton/following{/other_user}","gists_url":"https://api.github.com/users/derekhamilton/gists{/gist_id}","starred_url":"https://api.github.com/users/derekhamilton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/derekhamilton/subscriptions","organizations_url":"https://api.github.com/users/derekhamilton/orgs","repos_url":"https://api.github.com/users/derekhamilton/repos","events_url":"https://api.github.com/users/derekhamilton/events{/privacy}","received_events_url":"https://api.github.com/users/derekhamilton/received_events","type":"User","site_admin":false},"body":"Additional logic for handling pagination count if the query has a group by clause.\r\n\r\nInstead of the count on paginate being determined by\r\n```select count(*) from tablename group by column;```\r\n\r\nit queries using\r\n```select count(*) from (select * from tablename group by column) aggregator_query```","created_at":"2015-02-27T14:50:04Z","updated_at":"2015-03-07T17:20:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc146f483753244c8fa6574843d01fa8ea4afb7b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/laravel/framework/pulls/7648/commits","review_comments_url":"https://api.github.com/repos/laravel/framework/pulls/7648/comments","review_comment_url":"https://api.github.com/repos/laravel/framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/laravel/framework/issues/7648/comments","statuses_url":"https://api.github.com/repos/laravel/framework/statuses/8f84ee62b3969f04a6cc59bd782afc17f9bce414","head":{"label":"derekhamilton:5.0","ref":"5.0","sha":"8f84ee62b3969f04a6cc59bd782afc17f9bce414","user":{"login":"derekhamilton","id":272878,"avatar_url":"https://avatars.githubusercontent.com/u/272878?v=3","gravatar_id":"","url":"https://api.github.com/users/derekhamilton","html_url":"https://github.com/derekhamilton","followers_url":"https://api.github.com/users/derekhamilton/followers","following_url":"https://api.github.com/users/derekhamilton/following{/other_user}","gists_url":"https://api.github.com/users/derekhamilton/gists{/gist_id}","starred_url":"https://api.github.com/users/derekhamilton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/derekhamilton/subscriptions","organizations_url":"https://api.github.com/users/derekhamilton/orgs","repos_url":"https://api.github.com/users/derekhamilton/repos","events_url":"https://api.github.com/users/derekhamilton/events{/privacy}","received_events_url":"https://api.github.com/users/derekhamilton/received_events","type":"User","site_admin":false},"repo":{"id":31423579,"name":"framework","full_name":"derekhamilton/framework","owner":{"login":"derekhamilton","id":272878,"avatar_url":"https://avatars.githubusercontent.com/u/272878?v=3","gravatar_id":"","url":"https://api.github.com/users/derekhamilton","html_url":"https://github.com/derekhamilton","followers_url":"https://api.github.com/users/derekhamilton/followers","following_url":"https://api.github.com/users/derekhamilton/following{/other_user}","gists_url":"https://api.github.com/users/derekhamilton/gists{/gist_id}","starred_url":"https://api.github.com/users/derekhamilton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/derekhamilton/subscriptions","organizations_url":"https://api.github.com/users/derekhamilton/orgs","repos_url":"https://api.github.com/users/derekhamilton/repos","events_url":"https://api.github.com/users/derekhamilton/events{/privacy}","received_events_url":"https://api.github.com/users/derekhamilton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/derekhamilton/framework","description":"","fork":true,"url":"https://api.github.com/repos/derekhamilton/framework","forks_url":"https://api.github.com/repos/derekhamilton/framework/forks","keys_url":"https://api.github.com/repos/derekhamilton/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/derekhamilton/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/derekhamilton/framework/teams","hooks_url":"https://api.github.com/repos/derekhamilton/framework/hooks","issue_events_url":"https://api.github.com/repos/derekhamilton/framework/issues/events{/number}","events_url":"https://api.github.com/repos/derekhamilton/framework/events","assignees_url":"https://api.github.com/repos/derekhamilton/framework/assignees{/user}","branches_url":"https://api.github.com/repos/derekhamilton/framework/branches{/branch}","tags_url":"https://api.github.com/repos/derekhamilton/framework/tags","blobs_url":"https://api.github.com/repos/derekhamilton/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/derekhamilton/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/derekhamilton/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/derekhamilton/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/derekhamilton/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/derekhamilton/framework/languages","stargazers_url":"https://api.github.com/repos/derekhamilton/framework/stargazers","contributors_url":"https://api.github.com/repos/derekhamilton/framework/contributors","subscribers_url":"https://api.github.com/repos/derekhamilton/framework/subscribers","subscription_url":"https://api.github.com/repos/derekhamilton/framework/subscription","commits_url":"https://api.github.com/repos/derekhamilton/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/derekhamilton/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/derekhamilton/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/derekhamilton/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/derekhamilton/framework/contents/{+path}","compare_url":"https://api.github.com/repos/derekhamilton/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/derekhamilton/framework/merges","archive_url":"https://api.github.com/repos/derekhamilton/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/derekhamilton/framework/downloads","issues_url":"https://api.github.com/repos/derekhamilton/framework/issues{/number}","pulls_url":"https://api.github.com/repos/derekhamilton/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/derekhamilton/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/derekhamilton/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/derekhamilton/framework/labels{/name}","releases_url":"https://api.github.com/repos/derekhamilton/framework/releases{/id}","created_at":"2015-02-27T14:43:25Z","updated_at":"2015-03-07T00:28:49Z","pushed_at":"2015-03-07T00:28:48Z","git_url":"git://github.com/derekhamilton/framework.git","ssh_url":"git@github.com:derekhamilton/framework.git","clone_url":"https://github.com/derekhamilton/framework.git","svn_url":"https://github.com/derekhamilton/framework","homepage":"http://laravel.com","size":14069,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"5.0"}},"base":{"label":"laravel:5.0","ref":"5.0","sha":"ee5ee39885456568667e28ae152010d0ae03b092","user":{"login":"laravel","id":958072,"avatar_url":"https://avatars.githubusercontent.com/u/958072?v=3","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"repo":{"id":7548986,"name":"framework","full_name":"laravel/framework","owner":{"login":"laravel","id":958072,"avatar_url":"https://avatars.githubusercontent.com/u/958072?v=3","gravatar_id":"","url":"https://api.github.com/users/laravel","html_url":"https://github.com/laravel","followers_url":"https://api.github.com/users/laravel/followers","following_url":"https://api.github.com/users/laravel/following{/other_user}","gists_url":"https://api.github.com/users/laravel/gists{/gist_id}","starred_url":"https://api.github.com/users/laravel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laravel/subscriptions","organizations_url":"https://api.github.com/users/laravel/orgs","repos_url":"https://api.github.com/users/laravel/repos","events_url":"https://api.github.com/users/laravel/events{/privacy}","received_events_url":"https://api.github.com/users/laravel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/laravel/framework","description":"","fork":false,"url":"https://api.github.com/repos/laravel/framework","forks_url":"https://api.github.com/repos/laravel/framework/forks","keys_url":"https://api.github.com/repos/laravel/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/laravel/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/laravel/framework/teams","hooks_url":"https://api.github.com/repos/laravel/framework/hooks","issue_events_url":"https://api.github.com/repos/laravel/framework/issues/events{/number}","events_url":"https://api.github.com/repos/laravel/framework/events","assignees_url":"https://api.github.com/repos/laravel/framework/assignees{/user}","branches_url":"https://api.github.com/repos/laravel/framework/branches{/branch}","tags_url":"https://api.github.com/repos/laravel/framework/tags","blobs_url":"https://api.github.com/repos/laravel/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/laravel/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/laravel/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/laravel/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/laravel/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/laravel/framework/languages","stargazers_url":"https://api.github.com/repos/laravel/framework/stargazers","contributors_url":"https://api.github.com/repos/laravel/framework/contributors","subscribers_url":"https://api.github.com/repos/laravel/framework/subscribers","subscription_url":"https://api.github.com/repos/laravel/framework/subscription","commits_url":"https://api.github.com/repos/laravel/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/laravel/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/laravel/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/laravel/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/laravel/framework/contents/{+path}","compare_url":"https://api.github.com/repos/laravel/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/laravel/framework/merges","archive_url":"https://api.github.com/repos/laravel/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/laravel/framework/downloads","issues_url":"https://api.github.com/repos/laravel/framework/issues{/number}","pulls_url":"https://api.github.com/repos/laravel/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/laravel/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/laravel/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/laravel/framework/labels{/name}","releases_url":"https://api.github.com/repos/laravel/framework/releases{/id}","created_at":"2013-01-10T21:27:28Z","updated_at":"2015-03-07T13:36:58Z","pushed_at":"2015-03-07T03:19:19Z","git_url":"git://github.com/laravel/framework.git","ssh_url":"git@github.com:laravel/framework.git","clone_url":"https://github.com/laravel/framework.git","svn_url":"https://github.com/laravel/framework","homepage":"http://laravel.com","size":58821,"stargazers_count":3278,"watchers_count":3278,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1803,"mirror_url":null,"open_issues_count":72,"forks":1803,"open_issues":72,"watchers":3278,"default_branch":"5.0"}},"_links":{"self":{"href":"https://api.github.com/repos/laravel/framework/pulls/7648"},"html":{"href":"https://github.com/laravel/framework/pull/7648"},"issue":{"href":"https://api.github.com/repos/laravel/framework/issues/7648"},"comments":{"href":"https://api.github.com/repos/laravel/framework/issues/7648/comments"},"review_comments":{"href":"https://api.github.com/repos/laravel/framework/pulls/7648/comments"},"review_comment":{"href":"https://api.github.com/repos/laravel/framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/laravel/framework/pulls/7648/commits"},"statuses":{"href":"https://api.github.com/repos/laravel/framework/statuses/8f84ee62b3969f04a6cc59bd782afc17f9bce414"}}}}