@@ -21,21 +21,21 @@ discard block |
||
| 21 | 21 | public function up() |
| 22 | 22 | { |
| 23 | 23 | $this->schema() |
| 24 | - ->create($this->roles, function (Blueprint $table) { |
|
| 24 | + ->create($this->roles, function(Blueprint $table) { |
|
| 25 | 25 | $table->bigIncrements('id'); |
| 26 | 26 | $table->string('name')->unique(); |
| 27 | 27 | $table->timestamps(); |
| 28 | 28 | }); |
| 29 | 29 | |
| 30 | 30 | $this->schema() |
| 31 | - ->create($this->permissions, function (Blueprint $table) { |
|
| 31 | + ->create($this->permissions, function(Blueprint $table) { |
|
| 32 | 32 | $table->bigIncrements('id'); |
| 33 | 33 | $table->string('name')->unique(); |
| 34 | 34 | $table->timestamps(); |
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | 37 | $this->schema() |
| 38 | - ->create($this->user_roles, function (Blueprint $table) { |
|
| 38 | + ->create($this->user_roles, function(Blueprint $table) { |
|
| 39 | 39 | $table->unsignedBigInteger('user_id'); |
| 40 | 40 | $table->unsignedBigInteger('role_id'); |
| 41 | 41 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | 48 | $this->schema() |
| 49 | - ->create($this->role_permissions, function (Blueprint $table) { |
|
| 49 | + ->create($this->role_permissions, function(Blueprint $table) { |
|
| 50 | 50 | $table->unsignedBigInteger('role_id'); |
| 51 | 51 | $table->unsignedBigInteger('permission_id'); |
| 52 | 52 | |
@@ -10,14 +10,14 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function up() |
| 12 | 12 | { |
| 13 | - $this->schema()->table('roles', function (Blueprint $table) { |
|
| 13 | + $this->schema()->table('roles', function(Blueprint $table) { |
|
| 14 | 14 | $table->boolean('is_root')->default(false)->after('name'); |
| 15 | 15 | }); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function down() |
| 19 | 19 | { |
| 20 | - $this->schema()->table('roles', function (Blueprint $table) { |
|
| 20 | + $this->schema()->table('roles', function(Blueprint $table) { |
|
| 21 | 21 | $table->dropColumn('is_root'); |
| 22 | 22 | }); |
| 23 | 23 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | return $value; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - return $this->searchOr($model, $value, function () use ($exception, $value) { |
|
| 54 | + return $this->searchOr($model, $value, function() use ($exception, $value) { |
|
| 55 | 55 | throw new $exception($value); |
| 56 | 56 | }); |
| 57 | 57 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | protected function roleIsDoesntExist(): bool |
| 32 | 32 | { |
| 33 | - return ! $this->roleIsExist(); |
|
| 33 | + return !$this->roleIsExist(); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | protected function permissionIsExist(): bool |
@@ -40,6 +40,6 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | protected function permissionIsDoesntExist(): bool |
| 42 | 42 | { |
| 43 | - return ! $this->permissionIsExist(); |
|
| 43 | + return !$this->permissionIsExist(); |
|
| 44 | 44 | } |
| 45 | 45 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function hasRootRole(): bool |
| 23 | 23 | { |
| 24 | - return $this->cache(__FUNCTION__, function () { |
|
| 24 | + return $this->cache(__FUNCTION__, function() { |
|
| 25 | 25 | return $this->roles() |
| 26 | 26 | ->where('is_root', true) |
| 27 | 27 | ->exists(); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function hasRole(...$roles): bool |
| 103 | 103 | { |
| 104 | - return $this->cache(__FUNCTION__, function () use ($roles) { |
|
| 104 | + return $this->cache(__FUNCTION__, function() use ($roles) { |
|
| 105 | 105 | foreach (Arr::flatten($roles) as $role) { |
| 106 | 106 | if ($this->roles->contains('name', $role)) { |
| 107 | 107 | return true; |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function hasRoles(...$roles): bool |
| 121 | 121 | { |
| 122 | - return $this->cache(__FUNCTION__, function () use ($roles) { |
|
| 122 | + return $this->cache(__FUNCTION__, function() use ($roles) { |
|
| 123 | 123 | foreach (Arr::flatten($roles) as $role) { |
| 124 | - if (! $this->roles->contains('name', $role)) { |
|
| 124 | + if (!$this->roles->contains('name', $role)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function hasPermission($permission): bool |
| 139 | 139 | { |
| 140 | - return $this->cache(__FUNCTION__, function () use ($permission) { |
|
| 140 | + return $this->cache(__FUNCTION__, function() use ($permission) { |
|
| 141 | 141 | $permission = $this->permissionId($permission); |
| 142 | 142 | |
| 143 | 143 | return (bool) $this->roles() |
| 144 | - ->whereHas('permissions', function (Builder $builder) use ($permission) { |
|
| 144 | + ->whereHas('permissions', function(Builder $builder) use ($permission) { |
|
| 145 | 145 | $builder |
| 146 | 146 | ->where('id', $permission) |
| 147 | 147 | ->orWhere('name', $permission); |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function hasPermissions(...$permissions): bool |
| 159 | 159 | { |
| 160 | - return $this->cache(__FUNCTION__, function () use ($permissions) { |
|
| 160 | + return $this->cache(__FUNCTION__, function() use ($permissions) { |
|
| 161 | 161 | foreach (Arr::flatten($permissions) as $permission) { |
| 162 | - if (! $this->hasPermission($permission)) { |
|
| 162 | + if (!$this->hasPermission($permission)) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | protected function has($request, array $permissions): bool |
| 39 | 39 | { |
| 40 | 40 | foreach ($permissions as $permission) { |
| 41 | - if (! $request->user()->hasPermission($permission)) { |
|
| 41 | + if (!$request->user()->hasPermission($permission)) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -46,57 +46,57 @@ |
||
| 46 | 46 | |
| 47 | 47 | protected function blade() |
| 48 | 48 | { |
| 49 | - if (! Config::useBlade()) { |
|
| 49 | + if (!Config::useBlade()) { |
|
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /* Role */ |
| 54 | - Blade::directive('role', function ($role) { |
|
| 54 | + Blade::directive('role', function($role) { |
|
| 55 | 55 | return "<?php if(\auth()->check() && \auth()->user()->hasRole($role)) { ?>"; |
| 56 | 56 | }); |
| 57 | 57 | |
| 58 | - Blade::directive('endrole', function () { |
|
| 58 | + Blade::directive('endrole', function() { |
|
| 59 | 59 | return '<?php } ?>'; |
| 60 | 60 | }); |
| 61 | 61 | |
| 62 | 62 | /* Roles */ |
| 63 | - Blade::directive('role', function ($roles) { |
|
| 63 | + Blade::directive('role', function($roles) { |
|
| 64 | 64 | return "<?php if(\auth()->check() && \auth()->user()->hasRoles($roles)) { ?>"; |
| 65 | 65 | }); |
| 66 | 66 | |
| 67 | - Blade::directive('endroles', function () { |
|
| 67 | + Blade::directive('endroles', function() { |
|
| 68 | 68 | return '<?php } ?>'; |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | 71 | /* Permission */ |
| 72 | - Blade::directive('permission', function ($permission) { |
|
| 72 | + Blade::directive('permission', function($permission) { |
|
| 73 | 73 | return "<?php if(\auth()->check() && \auth()->user()->hasPermission($permission)) ?>"; |
| 74 | 74 | }); |
| 75 | 75 | |
| 76 | - Blade::directive('endpermission', function () { |
|
| 76 | + Blade::directive('endpermission', function() { |
|
| 77 | 77 | return '<?php } ?>'; |
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | 80 | /* Permissions */ |
| 81 | - Blade::directive('permissions', function ($permissions) { |
|
| 81 | + Blade::directive('permissions', function($permissions) { |
|
| 82 | 82 | return "<?php if(\auth()->check() && \auth()->user()->hasPermissions($permissions)) ?>"; |
| 83 | 83 | }); |
| 84 | 84 | |
| 85 | - Blade::directive('endpermissions', function () { |
|
| 85 | + Blade::directive('endpermissions', function() { |
|
| 86 | 86 | return '<?php } ?>'; |
| 87 | 87 | }); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | protected function can() |
| 91 | 91 | { |
| 92 | - if (! Config::useCanDirective()) { |
|
| 92 | + if (!Config::useCanDirective()) { |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | Permission::query() |
| 97 | 97 | ->get(['name']) |
| 98 | - ->each(function (Permission $permission) { |
|
| 99 | - Gate::define($permission->name, function (Authenticatable $user) use ($permission) { |
|
| 98 | + ->each(function(Permission $permission) { |
|
| 99 | + Gate::define($permission->name, function(Authenticatable $user) use ($permission) { |
|
| 100 | 100 | return $user->hasPermission($permission); |
| 101 | 101 | }); |
| 102 | 102 | }); |