{"action":"created","comment":{"url":"https://api.github.com/repos/framgia/tms_47/pulls/comments/54520215","id":54520215,"diff_hunk":"@@ -25,7 +36,26 @@ public function __construct()\n      */\n     public function index()\n     {\n-        $view = ($this->user->isSupervisor()) ? 'supervisor/home' : 'trainee/home';\n-        return view($view);\n+        $courses = $this->user->courses;\n+        $courseIds = $courses->lists('id');\n+        $usersId = UserCourse::byCourseIds($courseIds)->lists('user_id');\n+        $users = User::listTrainee($usersId)->trainees()->get();\n+        $activities = Activity::whereIn('user_id', $usersId)->with('user')->paginate(Activity::ACTIVITY_PER_PAGE);\n+        $subjectsIds = CourseSubject::whereIn('course_id', $courseIds)->lists('subject_id');\n+        $subjects = Subject::whereIn('id', $subjectsIds)->get();","path":"app/Http/Controllers/HomeController.php","position":45,"original_position":45,"commit_id":"3894f5f5fedb1b01afcfd9feec39f1acec6341d2","original_commit_id":"3894f5f5fedb1b01afcfd9feec39f1acec6341d2","user":{"login":"wataridori","id":1189893,"avatar_url":"https://avatars.githubusercontent.com/u/1189893?v=3","gravatar_id":"","url":"https://api.github.com/users/wataridori","html_url":"https://github.com/wataridori","followers_url":"https://api.github.com/users/wataridori/followers","following_url":"https://api.github.com/users/wataridori/following{/other_user}","gists_url":"https://api.github.com/users/wataridori/gists{/gist_id}","starred_url":"https://api.github.com/users/wataridori/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wataridori/subscriptions","organizations_url":"https://api.github.com/users/wataridori/orgs","repos_url":"https://api.github.com/users/wataridori/repos","events_url":"https://api.github.com/users/wataridori/events{/privacy}","received_events_url":"https://api.github.com/users/wataridori/received_events","type":"User","site_admin":false},"body":"You use all of the following codes just to get all subjects that belong to an user?\r\n```php\r\n$courses = $this->user->courses;\r\n$courseIds = $courses->lists('id');\r\n$subjectsIds = CourseSubject::whereIn('course_id', $courseIds)->lists('subject_id');\r\n$subjects = Subject::whereIn('id', $subjectsIds)->get();\r\n```\r\nIt is too verbose! Try to use Eloquent Relationship. ","created_at":"2016-03-01T03:59:58Z","updated_at":"2016-03-01T03:59:58Z","html_url":"https://github.com/framgia/tms_47/pull/33#discussion_r54520215","pull_request_url":"https://api.github.com/repos/framgia/tms_47/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/comments/54520215"},"html":{"href":"https://github.com/framgia/tms_47/pull/33#discussion_r54520215"},"pull_request":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/framgia/tms_47/pulls/33","id":61044818,"html_url":"https://github.com/framgia/tms_47/pull/33","diff_url":"https://github.com/framgia/tms_47/pull/33.diff","patch_url":"https://github.com/framgia/tms_47/pull/33.patch","issue_url":"https://api.github.com/repos/framgia/tms_47/issues/33","number":33,"state":"open","locked":false,"title":"Supervisor Dashboard","user":{"login":"karlpandacan","id":16317506,"avatar_url":"https://avatars.githubusercontent.com/u/16317506?v=3","gravatar_id":"","url":"https://api.github.com/users/karlpandacan","html_url":"https://github.com/karlpandacan","followers_url":"https://api.github.com/users/karlpandacan/followers","following_url":"https://api.github.com/users/karlpandacan/following{/other_user}","gists_url":"https://api.github.com/users/karlpandacan/gists{/gist_id}","starred_url":"https://api.github.com/users/karlpandacan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlpandacan/subscriptions","organizations_url":"https://api.github.com/users/karlpandacan/orgs","repos_url":"https://api.github.com/users/karlpandacan/repos","events_url":"https://api.github.com/users/karlpandacan/events{/privacy}","received_events_url":"https://api.github.com/users/karlpandacan/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-29T08:47:23Z","updated_at":"2016-03-01T03:59:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24b42424491b7232ba777e413f173c8d31af2f43","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/framgia/tms_47/pulls/33/commits","review_comments_url":"https://api.github.com/repos/framgia/tms_47/pulls/33/comments","review_comment_url":"https://api.github.com/repos/framgia/tms_47/pulls/comments{/number}","comments_url":"https://api.github.com/repos/framgia/tms_47/issues/33/comments","statuses_url":"https://api.github.com/repos/framgia/tms_47/statuses/3894f5f5fedb1b01afcfd9feec39f1acec6341d2","head":{"label":"karlpandacan:supervisor_dashboard","ref":"supervisor_dashboard","sha":"3894f5f5fedb1b01afcfd9feec39f1acec6341d2","user":{"login":"karlpandacan","id":16317506,"avatar_url":"https://avatars.githubusercontent.com/u/16317506?v=3","gravatar_id":"","url":"https://api.github.com/users/karlpandacan","html_url":"https://github.com/karlpandacan","followers_url":"https://api.github.com/users/karlpandacan/followers","following_url":"https://api.github.com/users/karlpandacan/following{/other_user}","gists_url":"https://api.github.com/users/karlpandacan/gists{/gist_id}","starred_url":"https://api.github.com/users/karlpandacan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlpandacan/subscriptions","organizations_url":"https://api.github.com/users/karlpandacan/orgs","repos_url":"https://api.github.com/users/karlpandacan/repos","events_url":"https://api.github.com/users/karlpandacan/events{/privacy}","received_events_url":"https://api.github.com/users/karlpandacan/received_events","type":"User","site_admin":false},"repo":{"id":51975173,"name":"tms_47","full_name":"karlpandacan/tms_47","owner":{"login":"karlpandacan","id":16317506,"avatar_url":"https://avatars.githubusercontent.com/u/16317506?v=3","gravatar_id":"","url":"https://api.github.com/users/karlpandacan","html_url":"https://github.com/karlpandacan","followers_url":"https://api.github.com/users/karlpandacan/followers","following_url":"https://api.github.com/users/karlpandacan/following{/other_user}","gists_url":"https://api.github.com/users/karlpandacan/gists{/gist_id}","starred_url":"https://api.github.com/users/karlpandacan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlpandacan/subscriptions","organizations_url":"https://api.github.com/users/karlpandacan/orgs","repos_url":"https://api.github.com/users/karlpandacan/repos","events_url":"https://api.github.com/users/karlpandacan/events{/privacy}","received_events_url":"https://api.github.com/users/karlpandacan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/karlpandacan/tms_47","description":"Framgia Training Management System (training)","fork":true,"url":"https://api.github.com/repos/karlpandacan/tms_47","forks_url":"https://api.github.com/repos/karlpandacan/tms_47/forks","keys_url":"https://api.github.com/repos/karlpandacan/tms_47/keys{/key_id}","collaborators_url":"https://api.github.com/repos/karlpandacan/tms_47/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/karlpandacan/tms_47/teams","hooks_url":"https://api.github.com/repos/karlpandacan/tms_47/hooks","issue_events_url":"https://api.github.com/repos/karlpandacan/tms_47/issues/events{/number}","events_url":"https://api.github.com/repos/karlpandacan/tms_47/events","assignees_url":"https://api.github.com/repos/karlpandacan/tms_47/assignees{/user}","branches_url":"https://api.github.com/repos/karlpandacan/tms_47/branches{/branch}","tags_url":"https://api.github.com/repos/karlpandacan/tms_47/tags","blobs_url":"https://api.github.com/repos/karlpandacan/tms_47/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/karlpandacan/tms_47/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/karlpandacan/tms_47/git/refs{/sha}","trees_url":"https://api.github.com/repos/karlpandacan/tms_47/git/trees{/sha}","statuses_url":"https://api.github.com/repos/karlpandacan/tms_47/statuses/{sha}","languages_url":"https://api.github.com/repos/karlpandacan/tms_47/languages","stargazers_url":"https://api.github.com/repos/karlpandacan/tms_47/stargazers","contributors_url":"https://api.github.com/repos/karlpandacan/tms_47/contributors","subscribers_url":"https://api.github.com/repos/karlpandacan/tms_47/subscribers","subscription_url":"https://api.github.com/repos/karlpandacan/tms_47/subscription","commits_url":"https://api.github.com/repos/karlpandacan/tms_47/commits{/sha}","git_commits_url":"https://api.github.com/repos/karlpandacan/tms_47/git/commits{/sha}","comments_url":"https://api.github.com/repos/karlpandacan/tms_47/comments{/number}","issue_comment_url":"https://api.github.com/repos/karlpandacan/tms_47/issues/comments{/number}","contents_url":"https://api.github.com/repos/karlpandacan/tms_47/contents/{+path}","compare_url":"https://api.github.com/repos/karlpandacan/tms_47/compare/{base}...{head}","merges_url":"https://api.github.com/repos/karlpandacan/tms_47/merges","archive_url":"https://api.github.com/repos/karlpandacan/tms_47/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/karlpandacan/tms_47/downloads","issues_url":"https://api.github.com/repos/karlpandacan/tms_47/issues{/number}","pulls_url":"https://api.github.com/repos/karlpandacan/tms_47/pulls{/number}","milestones_url":"https://api.github.com/repos/karlpandacan/tms_47/milestones{/number}","notifications_url":"https://api.github.com/repos/karlpandacan/tms_47/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/karlpandacan/tms_47/labels{/name}","releases_url":"https://api.github.com/repos/karlpandacan/tms_47/releases{/id}","deployments_url":"https://api.github.com/repos/karlpandacan/tms_47/deployments","created_at":"2016-02-18T03:15:37Z","updated_at":"2016-02-16T09:29:22Z","pushed_at":"2016-03-01T02:42:40Z","git_url":"git://github.com/karlpandacan/tms_47.git","ssh_url":"git@github.com:karlpandacan/tms_47.git","clone_url":"https://github.com/karlpandacan/tms_47.git","svn_url":"https://github.com/karlpandacan/tms_47","homepage":null,"size":192,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"framgia:develop","ref":"develop","sha":"b8bd71ce78eb27f2522d656e38361ceba5399aec","user":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"repo":{"id":51823815,"name":"tms_47","full_name":"framgia/tms_47","owner":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/framgia/tms_47","description":"Framgia Training Management System (training)","fork":false,"url":"https://api.github.com/repos/framgia/tms_47","forks_url":"https://api.github.com/repos/framgia/tms_47/forks","keys_url":"https://api.github.com/repos/framgia/tms_47/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framgia/tms_47/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framgia/tms_47/teams","hooks_url":"https://api.github.com/repos/framgia/tms_47/hooks","issue_events_url":"https://api.github.com/repos/framgia/tms_47/issues/events{/number}","events_url":"https://api.github.com/repos/framgia/tms_47/events","assignees_url":"https://api.github.com/repos/framgia/tms_47/assignees{/user}","branches_url":"https://api.github.com/repos/framgia/tms_47/branches{/branch}","tags_url":"https://api.github.com/repos/framgia/tms_47/tags","blobs_url":"https://api.github.com/repos/framgia/tms_47/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framgia/tms_47/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framgia/tms_47/git/refs{/sha}","trees_url":"https://api.github.com/repos/framgia/tms_47/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framgia/tms_47/statuses/{sha}","languages_url":"https://api.github.com/repos/framgia/tms_47/languages","stargazers_url":"https://api.github.com/repos/framgia/tms_47/stargazers","contributors_url":"https://api.github.com/repos/framgia/tms_47/contributors","subscribers_url":"https://api.github.com/repos/framgia/tms_47/subscribers","subscription_url":"https://api.github.com/repos/framgia/tms_47/subscription","commits_url":"https://api.github.com/repos/framgia/tms_47/commits{/sha}","git_commits_url":"https://api.github.com/repos/framgia/tms_47/git/commits{/sha}","comments_url":"https://api.github.com/repos/framgia/tms_47/comments{/number}","issue_comment_url":"https://api.github.com/repos/framgia/tms_47/issues/comments{/number}","contents_url":"https://api.github.com/repos/framgia/tms_47/contents/{+path}","compare_url":"https://api.github.com/repos/framgia/tms_47/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framgia/tms_47/merges","archive_url":"https://api.github.com/repos/framgia/tms_47/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framgia/tms_47/downloads","issues_url":"https://api.github.com/repos/framgia/tms_47/issues{/number}","pulls_url":"https://api.github.com/repos/framgia/tms_47/pulls{/number}","milestones_url":"https://api.github.com/repos/framgia/tms_47/milestones{/number}","notifications_url":"https://api.github.com/repos/framgia/tms_47/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framgia/tms_47/labels{/name}","releases_url":"https://api.github.com/repos/framgia/tms_47/releases{/id}","deployments_url":"https://api.github.com/repos/framgia/tms_47/deployments","created_at":"2016-02-16T09:29:22Z","updated_at":"2016-02-16T09:29:22Z","pushed_at":"2016-03-01T03:24:42Z","git_url":"git://github.com/framgia/tms_47.git","ssh_url":"git@github.com:framgia/tms_47.git","clone_url":"https://github.com/framgia/tms_47.git","svn_url":"https://github.com/framgia/tms_47","homepage":null,"size":328,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":3,"forks":6,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/33"},"html":{"href":"https://github.com/framgia/tms_47/pull/33"},"issue":{"href":"https://api.github.com/repos/framgia/tms_47/issues/33"},"comments":{"href":"https://api.github.com/repos/framgia/tms_47/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/framgia/tms_47/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/framgia/tms_47/statuses/3894f5f5fedb1b01afcfd9feec39f1acec6341d2"}}}}