diff --git a/app/Entities/Permission.php b/app/Entities/Permission.php index 5d664c0..2e841eb 100755 --- a/app/Entities/Permission.php +++ b/app/Entities/Permission.php @@ -14,5 +14,5 @@ class Permission extends \Spatie\Permission\Models\Permission /** * @var array */ - protected $fillable = ['name', 'uuid']; + protected $fillable = ['name', 'uuid', 'guard_name']; } diff --git a/app/Entities/Role.php b/app/Entities/Role.php index 7737c4f..ac64c04 100755 --- a/app/Entities/Role.php +++ b/app/Entities/Role.php @@ -15,5 +15,5 @@ class Role extends \Spatie\Permission\Models\Role /** * @var array */ - protected $fillable = ['name', 'uuid']; + protected $fillable = ['name', 'uuid', 'guard_name']; } diff --git a/app/Support/HasPermissionsUuid.php b/app/Support/HasPermissionsUuid.php index ffcd3e1..7f2265f 100644 --- a/app/Support/HasPermissionsUuid.php +++ b/app/Support/HasPermissionsUuid.php @@ -2,7 +2,8 @@ namespace App\Support; -use App\Entities\Permission; +use Spatie\Permission\Contracts\Permission; +use App\Entities\Permission as PermissionEntity; /** * Class HasPermissionsUuid. @@ -16,14 +17,14 @@ trait HasPermissionsUuid * * @return Permission */ - protected function getStoredPermission($permissions) + protected function getStoredPermission($permissions): Permission { if (is_string($permissions)) { - return app(Permission::class)->where('name', $permissions)->orWhere('uuid', $permissions)->first(); + return app(PermissionEntity::class)->where('name', $permissions)->orWhere('uuid', $permissions)->first(); } if (is_array($permissions)) { - return app(Permission::class)->whereIn('name', $permissions)->orWhereIn('uuid', $permissions)->get(); + return app(PermissionEntity::class)->whereIn('name', $permissions)->orWhereIn('uuid', $permissions)->get(); } return $permissions; diff --git a/app/Support/HasRolesUuid.php b/app/Support/HasRolesUuid.php index 24b1b47..25719cf 100644 --- a/app/Support/HasRolesUuid.php +++ b/app/Support/HasRolesUuid.php @@ -2,7 +2,8 @@ namespace App\Support; -use App\Entities\Role; +use App\Entities\Role as RoleEntity; +use Spatie\Permission\Contracts\Role; trait HasRolesUuid { @@ -11,10 +12,10 @@ trait HasRolesUuid * * @return Role */ - protected function getStoredRole($role) + protected function getStoredRole($role): Role { if (is_string($role)) { - return app(Role::class)->where('name', $role)->orWhere('uuid', $role)->first(); + return app(RoleEntity::class)->where('name', $role)->orWhere('uuid', $role)->first(); } return $role; diff --git a/composer.json b/composer.json index c8632f8..bde7ec4 100755 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ ], "require": { "php": ">=7.0.0", + "dingo/api": "1.0.*@dev", "laravel/framework": "5.4.*", "laravel/passport": "^3.0", "laravel/tinker": "~1.0", "predis/predis": "^1.1", - "dingo/api": "1.0.*@dev", - "spatie/laravel-permission": "^1.7", + "spatie/laravel-permission": "^2.4", "webpatser/laravel-uuid": "^2.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index b804c9a..9936ac1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "56f6d68eee6f34fec0790f06ff22ba47", - "content-hash": "fe2a8e0993cb895cbd3f65cea0fa4a48", + "content-hash": "d1ee1888d87c691f8b97e98b48728db1", "packages": [ { "name": "defuse/php-encryption", @@ -68,7 +67,7 @@ "security", "symmetric key cryptography" ], - "time": "2017-05-18 21:28:48" + "time": "2017-05-18T21:28:48+00:00" }, { "name": "dingo/api", @@ -198,7 +197,7 @@ "docs", "laravel" ], - "time": "2017-02-11 17:28:57" + "time": "2017-02-11T17:28:57+00:00" }, { "name": "dnoegel/php-xdg-base-dir", @@ -231,7 +230,7 @@ "MIT" ], "description": "implementation of xdg base directory specification for php", - "time": "2014-10-24 07:27:01" + "time": "2014-10-24T07:27:01+00:00" }, { "name": "doctrine/annotations", @@ -299,7 +298,7 @@ "docblock", "parser" ], - "time": "2017-02-24 16:22:25" + "time": "2017-02-24T16:22:25+00:00" }, { "name": "doctrine/inflector", @@ -366,7 +365,7 @@ "singularize", "string" ], - "time": "2015-11-06 14:35:42" + "time": "2015-11-06T14:35:42+00:00" }, { "name": "doctrine/lexer", @@ -420,7 +419,7 @@ "lexer", "parser" ], - "time": "2014-09-09 13:34:57" + "time": "2014-09-09T13:34:57+00:00" }, { "name": "erusev/parsedown", @@ -462,7 +461,7 @@ "markdown", "parser" ], - "time": "2017-05-14 14:47:48" + "time": "2017-05-14T14:47:48+00:00" }, { "name": "firebase/php-jwt", @@ -505,7 +504,7 @@ ], "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", "homepage": "https://github.com/firebase/php-jwt", - "time": "2016-07-18 04:51:16" + "time": "2016-07-18T04:51:16+00:00" }, { "name": "guzzlehttp/guzzle", @@ -570,7 +569,7 @@ "rest", "web service" ], - "time": "2017-06-22 18:50:49" + "time": "2017-06-22T18:50:49+00:00" }, { "name": "guzzlehttp/promises", @@ -621,7 +620,7 @@ "keywords": [ "promise" ], - "time": "2016-12-20 10:07:11" + "time": "2016-12-20T10:07:11+00:00" }, { "name": "guzzlehttp/psr7", @@ -686,7 +685,7 @@ "uri", "url" ], - "time": "2017-03-20 17:10:46" + "time": "2017-03-20T17:10:46+00:00" }, { "name": "jakub-onderka/php-console-color", @@ -729,7 +728,7 @@ "homepage": "http://www.acci.cz" } ], - "time": "2014-04-08 15:00:19" + "time": "2014-04-08T15:00:19+00:00" }, { "name": "jakub-onderka/php-console-highlighter", @@ -773,7 +772,7 @@ "homepage": "http://www.acci.cz/" } ], - "time": "2015-04-20 18:58:01" + "time": "2015-04-20T18:58:01+00:00" }, { "name": "laravel/framework", @@ -902,7 +901,7 @@ "framework", "laravel" ], - "time": "2017-06-30 13:43:07" + "time": "2017-06-30T13:43:07+00:00" }, { "name": "laravel/passport", @@ -971,7 +970,7 @@ "oauth", "passport" ], - "time": "2017-07-02 13:14:54" + "time": "2017-07-02T13:14:54+00:00" }, { "name": "laravel/tinker", @@ -1034,7 +1033,7 @@ "laravel", "psysh" ], - "time": "2017-06-01 16:31:26" + "time": "2017-06-01T16:31:26+00:00" }, { "name": "lcobucci/jwt", @@ -1092,7 +1091,7 @@ "JWS", "jwt" ], - "time": "2016-10-31 20:09:32" + "time": "2016-10-31T20:09:32+00:00" }, { "name": "league/event", @@ -1142,7 +1141,7 @@ "event", "listener" ], - "time": "2015-05-21 12:24:47" + "time": "2015-05-21T12:24:47+00:00" }, { "name": "league/flysystem", @@ -1225,7 +1224,7 @@ "sftp", "storage" ], - "time": "2017-04-28 10:15:08" + "time": "2017-04-28T10:15:08+00:00" }, { "name": "league/fractal", @@ -1289,7 +1288,7 @@ "league", "rest" ], - "time": "2017-03-12 01:28:43" + "time": "2017-03-12T01:28:43+00:00" }, { "name": "league/oauth2-server", @@ -1357,7 +1356,7 @@ "secure", "server" ], - "time": "2017-07-01 17:46:48" + "time": "2017-07-01T17:46:48+00:00" }, { "name": "monolog/monolog", @@ -1435,7 +1434,7 @@ "logging", "psr-3" ], - "time": "2017-06-19 01:22:40" + "time": "2017-06-19T01:22:40+00:00" }, { "name": "mtdowling/cron-expression", @@ -1479,7 +1478,7 @@ "cron", "schedule" ], - "time": "2017-01-23 04:29:33" + "time": "2017-01-23T04:29:33+00:00" }, { "name": "nesbot/carbon", @@ -1532,7 +1531,7 @@ "datetime", "time" ], - "time": "2017-01-16 07:55:07" + "time": "2017-01-16T07:55:07+00:00" }, { "name": "nikic/php-parser", @@ -1583,7 +1582,7 @@ "parser", "php" ], - "time": "2017-06-28 20:53:48" + "time": "2017-06-28T20:53:48+00:00" }, { "name": "paragonie/random_compat", @@ -1631,7 +1630,7 @@ "pseudorandom", "random" ], - "time": "2017-03-13 16:27:32" + "time": "2017-03-13T16:27:32+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1685,7 +1684,7 @@ "reflection", "static analysis" ], - "time": "2015-12-27 11:43:31" + "time": "2015-12-27T11:43:31+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -1730,7 +1729,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-09-30 07:12:33" + "time": "2016-09-30T07:12:33+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1777,7 +1776,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-11-25 06:54:22" + "time": "2016-11-25T06:54:22+00:00" }, { "name": "phpseclib/phpseclib", @@ -1869,7 +1868,7 @@ "x.509", "x509" ], - "time": "2017-06-05 06:31:10" + "time": "2017-06-05T06:31:10+00:00" }, { "name": "predis/predis", @@ -1919,7 +1918,7 @@ "predis", "redis" ], - "time": "2016-06-16 16:22:20" + "time": "2016-06-16T16:22:20+00:00" }, { "name": "psr/http-message", @@ -1969,7 +1968,7 @@ "request", "response" ], - "time": "2016-08-06 14:39:51" + "time": "2016-08-06T14:39:51+00:00" }, { "name": "psr/log", @@ -2016,7 +2015,7 @@ "psr", "psr-3" ], - "time": "2016-10-10 12:19:37" + "time": "2016-10-10T12:19:37+00:00" }, { "name": "psy/psysh", @@ -2089,7 +2088,7 @@ "interactive", "shell" ], - "time": "2017-07-06 14:53:52" + "time": "2017-07-06T14:53:52+00:00" }, { "name": "ramsey/uuid", @@ -2171,37 +2170,49 @@ "identifier", "uuid" ], - "time": "2017-03-26 20:37:53" + "time": "2017-03-26T20:37:53+00:00" }, { "name": "spatie/laravel-permission", - "version": "1.12.0", + "version": "2.4.2", "source": { "type": "git", "url": "https://github.com/spatie/laravel-permission.git", - "reference": "837ff988016824318efe30c32947146c393a273f" + "reference": "0c260f9fac3674a1c7e7c4cd78fd68a1df8adbff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/837ff988016824318efe30c32947146c393a273f", - "reference": "837ff988016824318efe30c32947146c393a273f", + "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/0c260f9fac3674a1c7e7c4cd78fd68a1df8adbff", + "reference": "0c260f9fac3674a1c7e7c4cd78fd68a1df8adbff", "shasum": "" }, "require": { - "illuminate/contracts": "~5.1.0|~5.2.0|~5.3.0|~5.4.0", - "laravel/framework": "~5.1.11|~5.2.0|~5.3.0|~5.4.0", - "php": ">=5.6.0" + "illuminate/auth": "~5.4.0", + "illuminate/container": "~5.4.0", + "illuminate/contracts": "~5.4.0", + "illuminate/database": "~5.4.0", + "php": ">=7.0" }, "require-dev": { "monolog/monolog": "^1.22", - "orchestra/testbench": "~3.3.0|~3.4.0", - "phpunit/phpunit": "^5.7.8" + "orchestra/testbench": "~3.4.2", + "phpunit/phpunit": "^6.0" }, "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Permission\\PermissionServiceProvider" + ] + } + }, "autoload": { "psr-4": { "Spatie\\Permission\\": "src" - } + }, + "files": [ + "src/helpers.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2215,7 +2226,7 @@ "role": "Developer" } ], - "description": "Permission handling for Laravel 5.1 and up", + "description": "Permission handling for Laravel 5.4 and up", "homepage": "https://github.com/spatie/laravel-permission", "keywords": [ "acl", @@ -2224,7 +2235,7 @@ "security", "spatie" ], - "time": "2017-03-14 19:14:04" + "time": "2017-08-11T10:32:18+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -2278,7 +2289,7 @@ "mail", "mailer" ], - "time": "2017-05-01 15:54:03" + "time": "2017-05-01T15:54:03+00:00" }, { "name": "symfony/console", @@ -2347,7 +2358,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-07-03 13:19:36" + "time": "2017-07-03T13:19:36+00:00" }, { "name": "symfony/css-selector", @@ -2400,7 +2411,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2017-05-01 15:01:29" + "time": "2017-05-01T15:01:29+00:00" }, { "name": "symfony/debug", @@ -2456,7 +2467,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2017-07-05 13:02:37" + "time": "2017-07-05T13:02:37+00:00" }, { "name": "symfony/event-dispatcher", @@ -2519,7 +2530,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-06-09 14:53:08" + "time": "2017-06-09T14:53:08+00:00" }, { "name": "symfony/finder", @@ -2568,7 +2579,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-06-01 21:01:25" + "time": "2017-06-01T21:01:25+00:00" }, { "name": "symfony/http-foundation", @@ -2621,7 +2632,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2017-06-24 09:29:48" + "time": "2017-06-24T09:29:48+00:00" }, { "name": "symfony/http-kernel", @@ -2707,7 +2718,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2017-07-05 13:28:15" + "time": "2017-07-05T13:28:15+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -2766,7 +2777,7 @@ "portable", "shim" ], - "time": "2017-06-09 14:24:12" + "time": "2017-06-09T14:24:12+00:00" }, { "name": "symfony/process", @@ -2815,7 +2826,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-07-03 08:12:02" + "time": "2017-07-03T08:12:02+00:00" }, { "name": "symfony/psr-http-message-bridge", @@ -2875,7 +2886,7 @@ "http-message", "psr-7" ], - "time": "2016-09-14 18:37:20" + "time": "2016-09-14T18:37:20+00:00" }, { "name": "symfony/routing", @@ -2953,7 +2964,7 @@ "uri", "url" ], - "time": "2017-06-24 09:29:48" + "time": "2017-06-24T09:29:48+00:00" }, { "name": "symfony/translation", @@ -3018,7 +3029,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2017-06-24 16:45:30" + "time": "2017-06-24T16:45:30+00:00" }, { "name": "symfony/var-dumper", @@ -3086,7 +3097,7 @@ "debug", "dump" ], - "time": "2017-07-05 13:02:37" + "time": "2017-07-05T13:02:37+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -3133,7 +3144,7 @@ ], "description": "CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.", "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", - "time": "2016-09-20 12:50:39" + "time": "2016-09-20T12:50:39+00:00" }, { "name": "vlucas/phpdotenv", @@ -3183,7 +3194,7 @@ "env", "environment" ], - "time": "2016-09-01 10:05:43" + "time": "2016-09-01T10:05:43+00:00" }, { "name": "webmozart/assert", @@ -3233,7 +3244,7 @@ "check", "validate" ], - "time": "2016-11-23 20:04:58" + "time": "2016-11-23T20:04:58+00:00" }, { "name": "webpatser/laravel-uuid", @@ -3287,7 +3298,7 @@ "keywords": [ "UUID RFC4122" ], - "time": "2017-06-26 09:33:47" + "time": "2017-06-26T09:33:47+00:00" }, { "name": "zendframework/zend-diactoros", @@ -3339,7 +3350,7 @@ "psr", "psr-7" ], - "time": "2017-04-06 16:18:34" + "time": "2017-04-06T16:18:34+00:00" } ], "packages-dev": [ @@ -3395,7 +3406,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "fzaninotto/faker", @@ -3443,7 +3454,7 @@ "faker", "fixtures" ], - "time": "2016-04-29 12:21:54" + "time": "2016-04-29T12:21:54+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -3488,7 +3499,7 @@ "keywords": [ "test" ], - "time": "2015-05-11 14:41:42" + "time": "2015-05-11T14:41:42+00:00" }, { "name": "mockery/mockery", @@ -3553,7 +3564,7 @@ "test double", "testing" ], - "time": "2017-02-28 12:52:32" + "time": "2017-02-28T12:52:32+00:00" }, { "name": "myclabs/deep-copy", @@ -3595,7 +3606,7 @@ "object", "object graph" ], - "time": "2017-04-12 18:52:22" + "time": "2017-04-12T18:52:22+00:00" }, { "name": "phpspec/prophecy", @@ -3658,7 +3669,7 @@ "spy", "stub" ], - "time": "2017-03-02 20:05:34" + "time": "2017-03-02T20:05:34+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3721,7 +3732,7 @@ "testing", "xunit" ], - "time": "2017-04-02 07:44:40" + "time": "2017-04-02T07:44:40+00:00" }, { "name": "phpunit/php-file-iterator", @@ -3768,7 +3779,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03 07:40:28" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", @@ -3809,7 +3820,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -3858,7 +3869,7 @@ "keywords": [ "timer" ], - "time": "2017-02-26 11:10:40" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", @@ -3907,7 +3918,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27 10:12:30" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", @@ -3989,7 +4000,7 @@ "testing", "xunit" ], - "time": "2017-06-21 08:11:54" + "time": "2017-06-21T08:11:54+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -4048,7 +4059,7 @@ "mock", "xunit" ], - "time": "2017-06-30 09:13:00" + "time": "2017-06-30T09:13:00+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -4093,7 +4104,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04 06:30:41" + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", @@ -4157,7 +4168,7 @@ "compare", "equality" ], - "time": "2017-01-29 09:50:25" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", @@ -4209,7 +4220,7 @@ "keywords": [ "diff" ], - "time": "2017-05-22 07:24:03" + "time": "2017-05-22T07:24:03+00:00" }, { "name": "sebastian/environment", @@ -4259,7 +4270,7 @@ "environment", "hhvm" ], - "time": "2016-11-26 07:53:53" + "time": "2016-11-26T07:53:53+00:00" }, { "name": "sebastian/exporter", @@ -4326,7 +4337,7 @@ "export", "exporter" ], - "time": "2016-11-19 08:54:04" + "time": "2016-11-19T08:54:04+00:00" }, { "name": "sebastian/global-state", @@ -4377,7 +4388,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/object-enumerator", @@ -4423,7 +4434,7 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-02-18 15:18:39" + "time": "2017-02-18T15:18:39+00:00" }, { "name": "sebastian/recursion-context", @@ -4476,7 +4487,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-11-19 07:33:16" + "time": "2016-11-19T07:33:16+00:00" }, { "name": "sebastian/resource-operations", @@ -4518,7 +4529,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28 20:34:47" + "time": "2015-07-28T20:34:47+00:00" }, { "name": "sebastian/version", @@ -4561,7 +4572,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-10-03 07:35:21" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/yaml", @@ -4616,7 +4627,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-06-15 12:58:50" + "time": "2017-06-15T12:58:50+00:00" } ], "aliases": [], diff --git a/config/laravel-permission.php b/config/laravel-permission.php deleted file mode 100644 index e38929d..0000000 --- a/config/laravel-permission.php +++ /dev/null @@ -1,142 +0,0 @@ - [ - - /* - |-------------------------------------------------------------------------- - | Permission Model - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | Eloquent model should be used to retrieve your permissions. Of course, it - | is often just the "Permission" model but you may use whatever you like. - | - | The model you want to use as a Permission model needs to implement the - | `Spatie\Permission\Contracts\Permission` contract. - | - */ - - 'permission' => \App\Entities\Permission::class, - - /* - |-------------------------------------------------------------------------- - | Role Model - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | Eloquent model should be used to retrieve your roles. Of course, it - | is often just the "Role" model but you may use whatever you like. - | - | The model you want to use as a Role model needs to implement the - | `Spatie\Permission\Contracts\Role` contract. - | - */ - - 'role' => \App\Entities\Role::class, - - ], - - /* - |-------------------------------------------------------------------------- - | Authorization Tables - |-------------------------------------------------------------------------- - */ - - 'table_names' => [ - - /* - |-------------------------------------------------------------------------- - | Users Table - |-------------------------------------------------------------------------- - | - | The table that your application uses for users. This table's model will - | be using the "HasRoles" and "HasPermissions" traits. - | - */ - 'users' => 'users', - - /* - |-------------------------------------------------------------------------- - | Roles Table - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | table should be used to retrieve your roles. We have chosen a basic - | default value but you may easily change it to any table you like. - | - */ - - 'roles' => 'roles', - - /* - |-------------------------------------------------------------------------- - | Permissions Table - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | table should be used to retrieve your permissions. We have chosen a basic - | default value but you may easily change it to any table you like. - | - */ - - 'permissions' => 'permissions', - - /* - |-------------------------------------------------------------------------- - | User Permissions Table - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | table should be used to retrieve your users permissions. We have chosen a - | basic default value but you may easily change it to any table you like. - | - */ - - 'user_has_permissions' => 'user_has_permissions', - - /* - |-------------------------------------------------------------------------- - | User Roles Table - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | table should be used to retrieve your users roles. We have chosen a - | basic default value but you may easily change it to any table you like. - | - */ - - 'user_has_roles' => 'user_has_roles', - - /* - |-------------------------------------------------------------------------- - | Role Permissions Table - |-------------------------------------------------------------------------- - | - | When using the "HasRoles" trait from this package, we need to know which - | table should be used to retrieve your roles permissions. We have chosen a - | basic default value but you may easily change it to any table you like. - | - */ - - 'role_has_permissions' => 'role_has_permissions', - - ], - - /* - * By default we'll make an entry in the application log when the permissions - * could not be loaded. Normally this only occurs while installing the packages. - * - * If for some reason you want to disable that logging, set this value to false. - */ - - 'log_registration_exception' => env('APP_ENV') !== 'testing', - -]; diff --git a/config/permission.php b/config/permission.php new file mode 100644 index 0000000..1e5cf9e --- /dev/null +++ b/config/permission.php @@ -0,0 +1,89 @@ + [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => \App\Entities\Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => \App\Entities\Role::class, + + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + /* + * By default all permissions will be cached for 24 hours unless a permission or + * role is updated. Then the cache will be flushed immediately. + */ + + 'cache_expiration_time' => 60 * 24, + + /* + * By default we'll make an entry in the application log when the permissions + * could not be loaded. Normally this only occurs while installing the packages. + * + * If for some reason you want to disable that logging, set this value to false. + */ + + 'log_registration_exception' => env('APP_ENV') !== 'testing', +]; diff --git a/database/migrations/2017_02_09_031936_create_permission_tables.php b/database/migrations/2017_02_09_031936_create_permission_tables.php index 0aff19e..cc8ad6f 100644 --- a/database/migrations/2017_02_09_031936_create_permission_tables.php +++ b/database/migrations/2017_02_09_031936_create_permission_tables.php @@ -12,68 +12,61 @@ class CreatePermissionTables extends Migration */ public function up() { - $config = config('laravel-permission.table_names'); + $tableNames = config('permission.table_names'); + $foreignKeys = config('permission.foreign_keys'); - Schema::create($config['roles'], function (Blueprint $table) { + Schema::create($tableNames['permissions'], function (Blueprint $table) { $table->increments('id'); - $table->string('name')->unique(); + $table->string('name'); + $table->string('guard_name'); $table->uuid('uuid')->index(); $table->timestamps(); }); - Schema::create($config['permissions'], function (Blueprint $table) { + Schema::create($tableNames['roles'], function (Blueprint $table) { $table->increments('id'); - $table->string('name')->unique(); + $table->string('name'); + $table->string('guard_name'); $table->uuid('uuid')->index(); $table->timestamps(); }); - Schema::create($config['user_has_permissions'], function (Blueprint $table) use ($config) { - $table->integer('user_id')->unsigned(); + Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $foreignKeys) { $table->integer('permission_id')->unsigned(); - - $table->foreign('user_id') - ->references('id') - ->on($config['users']) - ->onDelete('cascade'); + $table->morphs('model'); $table->foreign('permission_id') ->references('id') - ->on($config['permissions']) + ->on($tableNames['permissions']) ->onDelete('cascade'); - $table->primary(['user_id', 'permission_id']); + $table->primary(['permission_id', 'model_id', 'model_type']); }); - Schema::create($config['user_has_roles'], function (Blueprint $table) use ($config) { + Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $foreignKeys) { $table->integer('role_id')->unsigned(); - $table->integer('user_id')->unsigned(); + $table->morphs('model'); $table->foreign('role_id') ->references('id') - ->on($config['roles']) - ->onDelete('cascade'); - - $table->foreign('user_id') - ->references('id') - ->on($config['users']) + ->on($tableNames['roles']) ->onDelete('cascade'); - $table->primary(['role_id', 'user_id']); + $table->primary(['role_id', 'model_id', 'model_type']); }); - Schema::create($config['role_has_permissions'], function (Blueprint $table) use ($config) { + Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { $table->integer('permission_id')->unsigned(); $table->integer('role_id')->unsigned(); $table->foreign('permission_id') ->references('id') - ->on($config['permissions']) + ->on($tableNames['permissions']) ->onDelete('cascade'); $table->foreign('role_id') ->references('id') - ->on($config['roles']) + ->on($tableNames['roles']) ->onDelete('cascade'); $table->primary(['permission_id', 'role_id']); @@ -87,12 +80,12 @@ public function up() */ public function down() { - $config = config('laravel-permission.table_names'); + $tableNames = config('permission.table_names'); - Schema::drop($config['role_has_permissions']); - Schema::drop($config['user_has_roles']); - Schema::drop($config['user_has_permissions']); - Schema::drop($config['roles']); - Schema::drop($config['permissions']); + Schema::drop($tableNames['role_has_permissions']); + Schema::drop($tableNames['model_has_roles']); + Schema::drop($tableNames['model_has_permissions']); + Schema::drop($tableNames['roles']); + Schema::drop($tableNames['permissions']); } } diff --git a/tests/Feature/Users/UsersEndpointsTest.php b/tests/Feature/Users/UsersEndpointsTest.php index ec2c166..4e6486a 100755 --- a/tests/Feature/Users/UsersEndpointsTest.php +++ b/tests/Feature/Users/UsersEndpointsTest.php @@ -264,8 +264,8 @@ function test_it_can_create_user_with_associated_role() $response->assertStatus(201); $user = User::where('email', 'john@example.com')->first(); $roles->each(function($role) use ($user) { - $this->assertDatabaseHas('user_has_roles', [ - 'user_id' => $user->id, + $this->assertDatabaseHas('model_has_roles', [ + 'model_id' => $user->id, 'role_id' => $role->id ]); }); @@ -282,8 +282,8 @@ function test_it_updates_users_roles() ]); $response->assertStatus(200); $roles->each(function($role) use ($user) { - $this->assertDatabaseHas('user_has_roles', [ - 'user_id' => $user->id, + $this->assertDatabaseHas('model_has_roles', [ + 'model_id' => $user->id, 'role_id' => $role->id ]); }); @@ -301,8 +301,8 @@ function test_it_deletes_users_roles_if_empty_array_sent() ]); $response->assertStatus(200); $roles->each(function($role) use ($user) { - $this->assertDatabaseMissing('user_has_roles', [ - 'user_id' => $user->id, + $this->assertDatabaseMissing('model_has_roles', [ + 'model_id' => $user->id, 'role_id' => $role->id ]); });