{"action":"created","issue":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/985","repository_url":"https://api.github.com/repos/spatie/laravel-permission","labels_url":"https://api.github.com/repos/spatie/laravel-permission/issues/985/labels{/name}","comments_url":"https://api.github.com/repos/spatie/laravel-permission/issues/985/comments","events_url":"https://api.github.com/repos/spatie/laravel-permission/issues/985/events","html_url":"https://github.com/spatie/laravel-permission/issues/985","id":395067380,"node_id":"MDU6SXNzdWUzOTUwNjczODA=","number":985,"title":"How to use this on query builder","user":{"login":"jeraldpunx","id":5249781,"node_id":"MDQ6VXNlcjUyNDk3ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/5249781?v=4","gravatar_id":"","url":"https://api.github.com/users/jeraldpunx","html_url":"https://github.com/jeraldpunx","followers_url":"https://api.github.com/users/jeraldpunx/followers","following_url":"https://api.github.com/users/jeraldpunx/following{/other_user}","gists_url":"https://api.github.com/users/jeraldpunx/gists{/gist_id}","starred_url":"https://api.github.com/users/jeraldpunx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeraldpunx/subscriptions","organizations_url":"https://api.github.com/users/jeraldpunx/orgs","repos_url":"https://api.github.com/users/jeraldpunx/repos","events_url":"https://api.github.com/users/jeraldpunx/events{/privacy}","received_events_url":"https://api.github.com/users/jeraldpunx/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-01-01T09:05:03Z","updated_at":"2019-01-01T11:44:09Z","closed_at":"2019-01-01T11:44:09Z","author_association":"NONE","body":"I am still trying to figure out how to do this on laravel query builder cause I am using it on datatables, and only like this command I can do.\r\nfor example:\r\n`$users = User::select(['id', 'name', 'email', 'phone', 'created_at']);` \r\n\r\nHow to get the roles?\r\n\r\nAm I doing it right?\r\n\r\n```\r\n$users = User::join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')\r\n                        ->join('roles', 'model_has_roles.role_id', '=', 'roles.id')\r\n                        ->where('model_type', '=', 'App\\\\User');\r\n\r\nreturn $users->get();\r\n```\r\n\r\nI am using this package [datatables.yajrabox](https://datatables.yajrabox.com/eloquent/basic) to implement, and most of the tutorial implementation need `User::select` but when I try `User::all()` it's not working though.\r\n\r\n\r\nReally having hard time how to implement this. I just want to display it like this \r\n*Temporary Role Column*\r\n![image](https://user-images.githubusercontent.com/5249781/50571538-2ec8dc00-0de8-11e9-8467-89452f3db10b.png)\r\n\r\nThis is my current implementation on yajrabox datatable package, all I want is how to implement the user roles, just really need help. \r\n![image](https://user-images.githubusercontent.com/5249781/50571615-dc88ba80-0de9-11e9-800b-6f9a616bcf09.png)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/comments/450724079","html_url":"https://github.com/spatie/laravel-permission/issues/985#issuecomment-450724079","issue_url":"https://api.github.com/repos/spatie/laravel-permission/issues/985","id":450724079,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDcyNDA3OQ==","user":{"login":"jeraldpunx","id":5249781,"node_id":"MDQ6VXNlcjUyNDk3ODE=","avatar_url":"https://avatars0.githubusercontent.com/u/5249781?v=4","gravatar_id":"","url":"https://api.github.com/users/jeraldpunx","html_url":"https://github.com/jeraldpunx","followers_url":"https://api.github.com/users/jeraldpunx/followers","following_url":"https://api.github.com/users/jeraldpunx/following{/other_user}","gists_url":"https://api.github.com/users/jeraldpunx/gists{/gist_id}","starred_url":"https://api.github.com/users/jeraldpunx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeraldpunx/subscriptions","organizations_url":"https://api.github.com/users/jeraldpunx/orgs","repos_url":"https://api.github.com/users/jeraldpunx/repos","events_url":"https://api.github.com/users/jeraldpunx/events{/privacy}","received_events_url":"https://api.github.com/users/jeraldpunx/received_events","type":"User","site_admin":false},"created_at":"2019-01-01T11:44:09Z","updated_at":"2019-01-01T11:44:09Z","author_association":"NONE","body":"nevermind, figure it out\r\n```\r\npublic function getUsers()\r\n    {\r\n        $users = User::select(['id', 'name', 'email', 'phone', 'created_at'])->with('roles');\r\n\r\n        return Datatables::of($users)\r\n            ->editColumn('created_at', function ($user) {\r\n                return $user->created_at->format('Y/m/d');\r\n            })\r\n            ->filterColumn('created_at', function ($query, $keyword) {\r\n                $query->whereRaw(\"DATE_FORMAT(created_at,'%Y/%m/%d') like ?\", [\"%$keyword%\"]);\r\n            })\r\n            ->addColumn('role', function ($user) {\r\n                return '<a class=\"btn btn-primary\" href=\"#\">'. ucfirst($user->roles->first()->name) .'</a>';\r\n            })\r\n            ->addColumn('action', function ($user) {\r\n                return '<a href=\"'.route('admin.users.edit', $user->id).'\" class=\"btn btn-xs btn-primary\"><i class=\"fa fa-edit\"></i> Edit</a>\r\n                <a href=\"'.route('admin.users.destroy', $user->id).'\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-trash\"></i> Delete</a>';\r\n            })\r\n            ->editColumn('id', 'ID: {{$id}}')\r\n            ->make(true);\r\n    }\r\n```"}}
{"actor":{"display_login":"jeraldpunx"}}