{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/8559","labels_url":"https://api.github.com/repos/laravel/framework/issues/8559/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/8559/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/8559/events","html_url":"https://github.com/laravel/framework/issues/8559","id":70942591,"number":8559,"title":"Builder with a groupBy results in empty pagination->render()","user":{"login":"simonfranz","id":1003559,"avatar_url":"https://avatars.githubusercontent.com/u/1003559?v=3","gravatar_id":"","url":"https://api.github.com/users/simonfranz","html_url":"https://github.com/simonfranz","followers_url":"https://api.github.com/users/simonfranz/followers","following_url":"https://api.github.com/users/simonfranz/following{/other_user}","gists_url":"https://api.github.com/users/simonfranz/gists{/gist_id}","starred_url":"https://api.github.com/users/simonfranz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonfranz/subscriptions","organizations_url":"https://api.github.com/users/simonfranz/orgs","repos_url":"https://api.github.com/users/simonfranz/repos","events_url":"https://api.github.com/users/simonfranz/events{/privacy}","received_events_url":"https://api.github.com/users/simonfranz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-25T17:39:34Z","updated_at":"2015-04-25T18:50:46Z","closed_at":null,"body":"HI there, \r\n\r\nI think i have found a bug witht he pagination-component while using a group-by statement.\r\n\r\nMy sample model is quite simple \r\n```\r\nSong\r\n     id\r\n     name\r\n     artist_id\r\nArtist\r\n     id\r\n     name\r\n```\r\nIn my Controller do can do this query:\r\n```\r\n $songs = Song::select('songs.*')\r\n            ->join('artists', 'songs.artist_id', '=', 'artists.id')\r\n            ->groupBy('songs.id')\r\n```\r\nwhich results into this sql statement.\r\n```\r\nselect count(*),`songs`.* from `songs` inner join `artists` on `songs`.`artist_id` = `artists`.`id` group by `songs`.`id`\r\n```\r\n\r\nBy now this is all correct, but if i want to use $songs->paginate(25); the result is a LengthAwarePaginator, which looks like this:\r\n```\r\nLengthAwarePaginator {#28786 ▼\r\n  #total: 1\r\n  #lastPage: 1\r\n  #items: Collection {#28759 ▶}\r\n  #perPage: 25\r\n  #currentPage: 1\r\n  #path: \"myurl\"\r\n  #query: []\r\n  #fragment: null\r\n  #pageName: \"page\"\r\n}\r\n```\r\n\r\nMaybe you can already see, that the \"total\"- value is wrong. I think it's the problem, is that to get the total value its Illuminate\\Database\\Pagination\\Builder::getCountForPagination() is called. To get the total row-count a count(*) is added in front of the query, But through the group by in every row the first value is 1, to the result for getCountForPagination() is set to one and no pagination links are rendered, because there seems to be only 1 page. \r\n\r\nIs this behaviour by purpose? Is there a workaround for this?\r\n\r\nIn my application i do multiple joins over multiple tables to create a large query over multiple tables, so i have to call a group-by to get the get the grouped songs.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/96259613","html_url":"https://github.com/laravel/framework/issues/8559#issuecomment-96259613","issue_url":"https://api.github.com/repos/laravel/framework/issues/8559","id":96259613,"user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"created_at":"2015-04-25T18:50:46Z","updated_at":"2015-04-25T18:50:46Z","body":"Does https://github.com/laravel/framework/pull/8310 fix this for you>"}}