@@ -12,7 +12,7 @@ |
||
| 12 | 12 | public static function getModelForGuard(string $guard) |
| 13 | 13 | { |
| 14 | 14 | return collect(config('auth.guards')) |
| 15 | - ->map(function ($guard) { |
|
| 15 | + ->map(function($guard) { |
|
| 16 | 16 | return config("auth.providers.{$guard['provider']}.model"); |
| 17 | 17 | })->get($guard); |
| 18 | 18 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | __DIR__ . '/../config/permission.php' => $this->app->configPath() . '/permission.php', |
| 16 | 16 | ], 'config'); |
| 17 | 17 | |
| 18 | - if (! class_exists('CreatePermissionTables')) { |
|
| 18 | + if (!class_exists('CreatePermissionTables')) { |
|
| 19 | 19 | $timestamp = date('Y_m_d_His', time()); |
| 20 | 20 | |
| 21 | 21 | $this->publishes([ |
@@ -55,40 +55,40 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | protected function registerBladeExtensions() |
| 57 | 57 | { |
| 58 | - $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { |
|
| 59 | - $bladeCompiler->directive('role', function ($arguments) { |
|
| 58 | + $this->app->afterResolving('blade.compiler', function(BladeCompiler $bladeCompiler) { |
|
| 59 | + $bladeCompiler->directive('role', function($arguments) { |
|
| 60 | 60 | list($role, $guard) = explode(',', $arguments . ','); |
| 61 | 61 | |
| 62 | 62 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>"; |
| 63 | 63 | }); |
| 64 | - $bladeCompiler->directive('endrole', function () { |
|
| 64 | + $bladeCompiler->directive('endrole', function() { |
|
| 65 | 65 | return '<?php endif; ?>'; |
| 66 | 66 | }); |
| 67 | 67 | |
| 68 | - $bladeCompiler->directive('hasrole', function ($arguments) { |
|
| 68 | + $bladeCompiler->directive('hasrole', function($arguments) { |
|
| 69 | 69 | list($role, $guard) = explode(',', $arguments . ','); |
| 70 | 70 | |
| 71 | 71 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>"; |
| 72 | 72 | }); |
| 73 | - $bladeCompiler->directive('endhasrole', function () { |
|
| 73 | + $bladeCompiler->directive('endhasrole', function() { |
|
| 74 | 74 | return '<?php endif; ?>'; |
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | - $bladeCompiler->directive('hasanyrole', function ($arguments) { |
|
| 77 | + $bladeCompiler->directive('hasanyrole', function($arguments) { |
|
| 78 | 78 | list($roles, $guard) = explode(',', $arguments . ','); |
| 79 | 79 | |
| 80 | 80 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAnyRole({$roles})): ?>"; |
| 81 | 81 | }); |
| 82 | - $bladeCompiler->directive('endhasanyrole', function () { |
|
| 82 | + $bladeCompiler->directive('endhasanyrole', function() { |
|
| 83 | 83 | return '<?php endif; ?>'; |
| 84 | 84 | }); |
| 85 | 85 | |
| 86 | - $bladeCompiler->directive('hasallroles', function ($arguments) { |
|
| 86 | + $bladeCompiler->directive('hasallroles', function($arguments) { |
|
| 87 | 87 | list($roles, $guard) = explode(',', $arguments . ','); |
| 88 | 88 | |
| 89 | 89 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAllRoles({$roles})): ?>"; |
| 90 | 90 | }); |
| 91 | - $bladeCompiler->directive('endhasallroles', function () { |
|
| 91 | + $bladeCompiler->directive('endhasallroles', function() { |
|
| 92 | 92 | return '<?php endif; ?>'; |
| 93 | 93 | }); |
| 94 | 94 | }); |
@@ -9,11 +9,11 @@ |
||
| 9 | 9 | { |
| 10 | 10 | public static function bootRefreshesPermissionCache() |
| 11 | 11 | { |
| 12 | - static::saved(function (Model $model) { |
|
| 12 | + static::saved(function(Model $model) { |
|
| 13 | 13 | app(PermissionRegistrar::class)->forgetCachedPermissions(); |
| 14 | 14 | }); |
| 15 | 15 | |
| 16 | - static::deleted(function (Model $model) { |
|
| 16 | + static::deleted(function(Model $model) { |
|
| 17 | 17 | app(PermissionRegistrar::class)->forgetCachedPermissions(); |
| 18 | 18 | }); |
| 19 | 19 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public static function bootHasRoles() |
| 17 | 17 | { |
| 18 | - static::deleting(function (Model $model) { |
|
| 18 | + static::deleting(function(Model $model) { |
|
| 19 | 19 | foreach ($model->roles as $role) { |
| 20 | 20 | $role->users()->detach($model); |
| 21 | 21 | } |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | $roles = collect($roles); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if (! $roles instanceof Collection) { |
|
| 58 | + if (!$roles instanceof Collection) { |
|
| 59 | 59 | $roles = collect([$roles]); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $roles = $roles->map(function ($role) { |
|
| 62 | + $roles = $roles->map(function($role) { |
|
| 63 | 63 | if ($role instanceof Role) { |
| 64 | 64 | return $role; |
| 65 | 65 | } |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $roles = collect($roles) |
| 83 | 83 | ->flatten() |
| 84 | - ->map(function ($role) { |
|
| 84 | + ->map(function($role) { |
|
| 85 | 85 | return $this->getStoredRole($role); |
| 86 | 86 | }) |
| 87 | - ->each(function ($role) { |
|
| 87 | + ->each(function($role) { |
|
| 88 | 88 | $this->ensureModelSharesGuard($role); |
| 89 | 89 | }) |
| 90 | 90 | ->all(); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | return $this->roles->contains('id', $roles->id); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $roles = collect()->make($roles)->map(function ($role) { |
|
| 190 | + $roles = collect()->make($roles)->map(function($role) { |
|
| 191 | 191 | return $role instanceof Role ? $role->name : $role; |
| 192 | 192 | }); |
| 193 | 193 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | public function getPermissionsViaRoles(): Collection |
| 279 | 279 | { |
| 280 | 280 | return $this->load('roles', 'roles.permissions') |
| 281 | - ->roles->flatMap(function (Role $role) { |
|
| 281 | + ->roles->flatMap(function(Role $role) { |
|
| 282 | 282 | return $role->permissions; |
| 283 | 283 | })->sort()->values(); |
| 284 | 284 | } |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | $permissions = collect($permissions) |
| 24 | 24 | ->flatten() |
| 25 | - ->map(function ($permission) { |
|
| 25 | + ->map(function($permission) { |
|
| 26 | 26 | return $this->getStoredPermission($permission); |
| 27 | 27 | }) |
| 28 | - ->each(function ($permission) { |
|
| 28 | + ->each(function($permission) { |
|
| 29 | 29 | $this->ensureModelSharesGuard($permission); |
| 30 | 30 | }) |
| 31 | 31 | ->all(); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | protected function ensureModelSharesGuard(Model $roleOrPermission) |
| 89 | 89 | { |
| 90 | - if (! $this->getGuardNames()->contains($roleOrPermission->guard_name)) { |
|
| 90 | + if (!$this->getGuardNames()->contains($roleOrPermission->guard_name)) { |
|
| 91 | 91 | throw GuardDoesNotMatch::create($roleOrPermission->guard_name, $this->getGuardNames()); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return collect(config('auth.guards')) |
| 102 | - ->map(function ($guard) { |
|
| 102 | + ->map(function($guard) { |
|
| 103 | 103 | return config("auth.providers.{$guard['provider']}.model"); |
| 104 | 104 | }) |
| 105 | - ->filter(function ($model) { |
|
| 105 | + ->filter(function($model) { |
|
| 106 | 106 | return get_class($this) === $model; |
| 107 | 107 | }) |
| 108 | 108 | ->keys(); |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | public function registerPermissions(): bool |
| 35 | 35 | { |
| 36 | 36 | try { |
| 37 | - $this->getPermissions()->map(function (Permission $permission) { |
|
| 38 | - $this->gate->define($permission->name, function (Model $user) use ($permission) { |
|
| 37 | + $this->getPermissions()->map(function(Permission $permission) { |
|
| 38 | + $this->gate->define($permission->name, function(Model $user) use ($permission) { |
|
| 39 | 39 | return $user->hasPermissionTo($permission); |
| 40 | 40 | }); |
| 41 | 41 | }); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public function getPermissions(): Collection |
| 62 | 62 | { |
| 63 | - return $this->cache->remember($this->cacheKey, config('permission.cache_expiration_time'), function () { |
|
| 63 | + return $this->cache->remember($this->cacheKey, config('permission.cache_expiration_time'), function() { |
|
| 64 | 64 | return app(Permission::class)->with('roles')->get(); |
| 65 | 65 | }); |
| 66 | 66 | } |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | |
| 74 | 74 | $permission = static::getPermissions()->where('name', $name)->where('guard_name', $guardName)->first(); |
| 75 | 75 | |
| 76 | - if (! $permission) { |
|
| 76 | + if (!$permission) { |
|
| 77 | 77 | throw PermissionDoesNotExist::create($name, $guardName); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $role = static::where('name', $name)->where('guard_name', $guardName)->first(); |
| 75 | 75 | |
| 76 | - if (! $role) { |
|
| 76 | + if (!$role) { |
|
| 77 | 77 | throw RoleDoesNotExist::create($name); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $permission = app(Permission::class)->findByName($permission, $this->getDefaultGuardName()); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if (! $this->getGuardNames()->contains($permission->guard_name)) { |
|
| 98 | + if (!$this->getGuardNames()->contains($permission->guard_name)) { |
|
| 99 | 99 | throw GuardDoesNotMatch::create($permission->guard_name, $this->getGuardNames()); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | |
| 16 | 16 | $permission = is_array($permission) ? $permission : explode('|', $permission); |
| 17 | 17 | |
| 18 | - if (! Auth::user()->hasAnyPermission(...$permission)) { |
|
| 18 | + if (!Auth::user()->hasAnyPermission(...$permission)) { |
|
| 19 | 19 | abort(403); |
| 20 | 20 | } |
| 21 | 21 | |