{"_id":"577256010a6d610e00de9e3b","category":{"_id":"576ec7b7560eef0e00cd3096","version":"576ebdb79c84a31900958abd","__v":0,"project":"576ebdb79c84a31900958aba","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-06-25T18:04:39.266Z","from_sync":false,"order":3,"slug":"deployment","title":"Basics"},"parentDoc":null,"version":{"_id":"576ebdb79c84a31900958abd","project":"576ebdb79c84a31900958aba","__v":10,"createdAt":"2016-06-25T17:21:59.854Z","releaseDate":"2016-06-25T17:21:59.854Z","categories":["576ebdb79c84a31900958abe","576ebfc59c84a31900958ac4","576ec32f52f96619007cfb9a","576ec7b7560eef0e00cd3096","576ed4249c84a31900958add","576ed429560eef0e00cd30a3","576ed43a52f96619007cfbb5","576ed44d5a8c72170082b794","577212f20da40019004f0816","57725c7e0a6d610e00de9e4c"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.3.0","version":"3.3"},"__v":10,"githubsync":"","project":"576ebdb79c84a31900958aba","user":"576ebd239c84a31900958ab9","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-06-28T10:48:33.271Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Essentially, the Auth class offered by Laravel is already good enough for normal usage. Orchestra Platform only extends the default operation and allow a user to be link with one or many roles.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Default Roles\"\n}\n[/block]\nBy default, Orchestra Platform require two user roles to be available. This roles can be modified, rename but it can't be deleted unless a different role is replaced as the default.\n\nYou can override the default config under `resources/config/packages/orchestra/foundation/config.php` (see [Configuration](doc:configuration) for guide on publishing the config file).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nreturn [\\n  \\n  /* ... */\\n  \\n\\t'roles' => [\\n    'admin' => 1,\\n    'member' => 2,\\n\\t],\\n];\",\n      \"language\": \"php\",\n      \"name\": \"config.php\"\n    }\n  ]\n}\n[/block]\nOr access it from the Control Extension configuration page:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/CbaGSl97QGuYeKJ2MT3S_Screen%20Shot%202016-06-28%20at%2011.09.04%20PM.png\",\n        \"Screen Shot 2016-06-28 at 11.09.04 PM.png\",\n        \"2032\",\n        \"1169\",\n        \"#53acfb\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n## Accessing the Roles\n\nYou can access the roles via eloquent:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nuse Orchestra\\\\Model\\\\Role;\\n\\n$member = Role::member();\\n\\n$admin = Role::admin();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Retrieving Roles\"\n}\n[/block]\nRetrieve user's roles is as simple as, which would return an instance of `Illuminate\\Support\\Collection`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$roles = Auth::roles();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Checking Roles\"\n}\n[/block]\nThere basically a few supported helpers to check roles:\n\n* [is()](#is)\n* [isAny()](#isany)\n* [isNot()](#isnot)\n* [isNotAny()](#isnotany)\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"is()\"\n}\n[/block]\nCheck if user has all of the following roles.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nif (Auth::is(['admin', 'editor'])) {\\n\\techo \\\"User is an admin and editor\\\";\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"isAny()\"\n}\n[/block]\nCheck if user is any of the following roles.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nif (Auth::isAny(['member', 'admin'])) {\\n\\techo \\\"User is a member or admin\\\";\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"isNot()\"\n}\n[/block]\nCheck if user is not of the following roles.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nif (Auth::isNot(['admin', 'editor'])) {\\n\\techo \\\"User isn't an admin and editor\\\";\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"fn\",\n  \"title\": \"isNotAny()\"\n}\n[/block]\nCheck if user has none any of the following roles.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nif (Auth::isNotAny(['member', 'admin'])) {\\n\\techo \\\"User isn't a member or admin\\\";\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"user-roles","type":"basic","title":"User Roles"}
Essentially, the Auth class offered by Laravel is already good enough for normal usage. Orchestra Platform only extends the default operation and allow a user to be link with one or many roles. [block:api-header] { "type": "basic", "title": "Default Roles" } [/block] By default, Orchestra Platform require two user roles to be available. This roles can be modified, rename but it can't be deleted unless a different role is replaced as the default. You can override the default config under `resources/config/packages/orchestra/foundation/config.php` (see [Configuration](doc:configuration) for guide on publishing the config file). [block:code] { "codes": [ { "code": "<?php\n\nreturn [\n \n /* ... */\n \n\t'roles' => [\n 'admin' => 1,\n 'member' => 2,\n\t],\n];", "language": "php", "name": "config.php" } ] } [/block] Or access it from the Control Extension configuration page: [block:image] { "images": [ { "image": [ "https://files.readme.io/CbaGSl97QGuYeKJ2MT3S_Screen%20Shot%202016-06-28%20at%2011.09.04%20PM.png", "Screen Shot 2016-06-28 at 11.09.04 PM.png", "2032", "1169", "#53acfb", "" ] } ] } [/block] ## Accessing the Roles You can access the roles via eloquent: [block:code] { "codes": [ { "code": "<?php\n\nuse Orchestra\\Model\\Role;\n\n$member = Role::member();\n\n$admin = Role::admin();", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Retrieving Roles" } [/block] Retrieve user's roles is as simple as, which would return an instance of `Illuminate\Support\Collection`: [block:code] { "codes": [ { "code": "<?php\n\n$roles = Auth::roles();", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Checking Roles" } [/block] There basically a few supported helpers to check roles: * [is()](#is) * [isAny()](#isany) * [isNot()](#isnot) * [isNotAny()](#isnotany) [block:api-header] { "type": "fn", "title": "is()" } [/block] Check if user has all of the following roles. [block:code] { "codes": [ { "code": "<?php\n\nif (Auth::is(['admin', 'editor'])) {\n\techo \"User is an admin and editor\";\n}", "language": "php" } ] } [/block] [block:api-header] { "type": "fn", "title": "isAny()" } [/block] Check if user is any of the following roles. [block:code] { "codes": [ { "code": "<?php\n\nif (Auth::isAny(['member', 'admin'])) {\n\techo \"User is a member or admin\";\n}", "language": "php" } ] } [/block] [block:api-header] { "type": "fn", "title": "isNot()" } [/block] Check if user is not of the following roles. [block:code] { "codes": [ { "code": "<?php\n\nif (Auth::isNot(['admin', 'editor'])) {\n\techo \"User isn't an admin and editor\";\n}", "language": "php" } ] } [/block] [block:api-header] { "type": "fn", "title": "isNotAny()" } [/block] Check if user has none any of the following roles. [block:code] { "codes": [ { "code": "<?php\n\nif (Auth::isNotAny(['member', 'admin'])) {\n\techo \"User isn't a member or admin\";\n}", "language": "php" } ] } [/block]