{"action":"created","issue":{"url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/81","repository_url":"https://api.github.com/repos/cmgmyr/laravel-messenger","labels_url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/81/comments","events_url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/81/events","html_url":"https://github.com/cmgmyr/laravel-messenger/issues/81","id":109413344,"number":81,"title":"Messenger makes huge number of database queries in view file","user":{"login":"tim-peterson","id":1173307,"avatar_url":"https://avatars.githubusercontent.com/u/1173307?v=3","gravatar_id":"","url":"https://api.github.com/users/tim-peterson","html_url":"https://github.com/tim-peterson","followers_url":"https://api.github.com/users/tim-peterson/followers","following_url":"https://api.github.com/users/tim-peterson/following{/other_user}","gists_url":"https://api.github.com/users/tim-peterson/gists{/gist_id}","starred_url":"https://api.github.com/users/tim-peterson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tim-peterson/subscriptions","organizations_url":"https://api.github.com/users/tim-peterson/orgs","repos_url":"https://api.github.com/users/tim-peterson/repos","events_url":"https://api.github.com/users/tim-peterson/events{/privacy}","received_events_url":"https://api.github.com/users/tim-peterson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cmgmyr/laravel-messenger/milestones/1","html_url":"https://github.com/cmgmyr/laravel-messenger/milestones/V3","labels_url":"https://api.github.com/repos/cmgmyr/laravel-messenger/milestones/1/labels","id":1206298,"number":1,"title":"V3","description":"The V3 rewrite of this package will take a more DDD approach to messages. The idea is to provide developers with code and (hopefully) inspire better practices in their own apps.","creator":{"login":"cmgmyr","id":4693481,"avatar_url":"https://avatars.githubusercontent.com/u/4693481?v=3","gravatar_id":"","url":"https://api.github.com/users/cmgmyr","html_url":"https://github.com/cmgmyr","followers_url":"https://api.github.com/users/cmgmyr/followers","following_url":"https://api.github.com/users/cmgmyr/following{/other_user}","gists_url":"https://api.github.com/users/cmgmyr/gists{/gist_id}","starred_url":"https://api.github.com/users/cmgmyr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmgmyr/subscriptions","organizations_url":"https://api.github.com/users/cmgmyr/orgs","repos_url":"https://api.github.com/users/cmgmyr/repos","events_url":"https://api.github.com/users/cmgmyr/events{/privacy}","received_events_url":"https://api.github.com/users/cmgmyr/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":1,"state":"open","created_at":"2015-07-14T04:02:04Z","updated_at":"2015-10-05T15:38:15Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2015-10-02T01:03:00Z","updated_at":"2016-02-16T14:40:22Z","closed_at":null,"body":"I've noticed in testing that creating multiple, say 10-20, messages results in hundreds of database queries using the example view, `index.blade.php`, most of them being repeat queries. This is happening in the `foreach` loop not surprisingly. I really don't think database calls should be happening in the view file (its not the MVC-way) so I'm wondering how the code base can be cleaned up. \r\n\r\n<img width=\"866\" alt=\"screen shot 2015-10-01 at 8 59 49 pm\" src=\"https://cloud.githubusercontent.com/assets/1173307/10237443/7b88f820-687f-11e5-9b04-c68de6e12d32.png\">\r\n"},"comment":{"url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/comments/184705230","html_url":"https://github.com/cmgmyr/laravel-messenger/issues/81#issuecomment-184705230","issue_url":"https://api.github.com/repos/cmgmyr/laravel-messenger/issues/81","id":184705230,"user":{"login":"divdax","id":1456739,"avatar_url":"https://avatars.githubusercontent.com/u/1456739?v=3","gravatar_id":"","url":"https://api.github.com/users/divdax","html_url":"https://github.com/divdax","followers_url":"https://api.github.com/users/divdax/followers","following_url":"https://api.github.com/users/divdax/following{/other_user}","gists_url":"https://api.github.com/users/divdax/gists{/gist_id}","starred_url":"https://api.github.com/users/divdax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divdax/subscriptions","organizations_url":"https://api.github.com/users/divdax/orgs","repos_url":"https://api.github.com/users/divdax/repos","events_url":"https://api.github.com/users/divdax/events{/privacy}","received_events_url":"https://api.github.com/users/divdax/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T14:40:22Z","updated_at":"2016-02-16T14:40:22Z","body":"@robbiepaul Thank you but one thing is wrong. This doesn't return the latest message:\r\n```\r\npublic function getLatestMessageAttribute()\r\n{\r\n        return $this->messages->first();\r\n}\r\n```"}}