@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('levels', function (Blueprint $table) { |
|
| 16 | + Schema::create('levels', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('name')->unique(); |
| 19 | 19 | $table->string('label')->nullable(); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::table(config('laravel-acl.authTable'), function (Blueprint $table) { |
|
| 15 | + Schema::table(config('laravel-acl.authTable'), function(Blueprint $table) { |
|
| 16 | 16 | $table->integer('level_id')->unsigned()->nullable(); |
| 17 | 17 | |
| 18 | 18 | $table->index('level_id'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function down() |
| 29 | 29 | { |
| 30 | - Schema::table(config('laravel-acl.authTable'), function (Blueprint $table) { |
|
| 30 | + Schema::table(config('laravel-acl.authTable'), function(Blueprint $table) { |
|
| 31 | 31 | $table->dropForeign(['level_id']); |
| 32 | 32 | $table->dropColumn('level_id'); |
| 33 | 33 | }); |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('permission_' . str_singular(config('laravel-acl.authTable')), function (Blueprint $table) { |
|
| 16 | + Schema::create('permission_' . str_singular(config('laravel-acl.authTable')), function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->integer('permission_id')->unsigned(); |
| 19 | 19 | $table->integer(str_singular(config('laravel-acl.authTable')) . '_id')->unsigned(); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function down() |
| 38 | 38 | { |
| 39 | - Schema::table('permission_' . str_singular(config('laravel-acl.authTable')), function (Blueprint $table) { |
|
| 39 | + Schema::table('permission_' . str_singular(config('laravel-acl.authTable')), function(Blueprint $table) { |
|
| 40 | 40 | $table->dropForeign(['permission_id']); |
| 41 | 41 | $table->dropForeign([str_singular(config('laravel-acl.authTable')) . '_id']); |
| 42 | 42 | }); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('permissions', function (Blueprint $table) { |
|
| 16 | + Schema::create('permissions', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('name')->unique(); |
| 19 | 19 | $table->string('label')->nullable(); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | 16 | if (!Schema::hasTable('users')) { |
| 17 | - Schema::create('users', function (Blueprint $table) { |
|
| 17 | + Schema::create('users', function(Blueprint $table) { |
|
| 18 | 18 | $table->increments('id'); |
| 19 | 19 | $table->string('name'); |
| 20 | 20 | $table->string('email')->unique(); |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | { |
| 135 | 135 | parent::boot(); |
| 136 | 136 | |
| 137 | - static::deleting(function ($permission) { |
|
| 137 | + static::deleting(function($permission) { |
|
| 138 | 138 | $permission->users()->detach(); |
| 139 | 139 | $permission->level()->dissociate()->save(); |
| 140 | 140 | }); |
@@ -99,11 +99,13 @@ |
||
| 99 | 99 | */ |
| 100 | 100 | protected function getUser($user) |
| 101 | 101 | { |
| 102 | - if (is_int($user)) |
|
| 103 | - $user = config('laravel-acl.user')::find($user); |
|
| 102 | + if (is_int($user)) { |
|
| 103 | + $user = config('laravel-acl.user')::find($user); |
|
| 104 | + } |
|
| 104 | 105 | |
| 105 | - if (!$user) |
|
| 106 | - throw new UserNotFoundException; |
|
| 106 | + if (!$user) { |
|
| 107 | + throw new UserNotFoundException; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | return $user; |
| 109 | 111 | } |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | { |
| 49 | 49 | parent::boot(); |
| 50 | 50 | |
| 51 | - static::deleting(function ($level) { |
|
| 51 | + static::deleting(function($level) { |
|
| 52 | 52 | $level->permissions()->where('level_id', $level->id)->update(['level_id' => null]); |
| 53 | 53 | foreach ($level->users as $user) { |
| 54 | 54 | $user->level()->dissociate()->save(); |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | return \Cache::remember( |
| 50 | 50 | 'laravel-acl.getNegatedPermissionsForUser_' . $this->id, |
| 51 | 51 | config('laravel-acl.cacheMinutes'), |
| 52 | - function () { |
|
| 52 | + function() { |
|
| 53 | 53 | return $this->cacheGetNegatedPermissions(); |
| 54 | 54 | } |
| 55 | 55 | ); |
@@ -21,8 +21,7 @@ discard block |
||
| 21 | 21 | $level = $this->getLevel($level); |
| 22 | 22 | |
| 23 | 23 | return get_class($this) == config('laravel-acl.level') ? |
| 24 | - $this->name == $level->name : |
|
| 25 | - $this->level->name == $level->name; |
|
| 24 | + $this->name == $level->name : $this->level->name == $level->name; |
|
| 26 | 25 | } |
| 27 | 26 | |
| 28 | 27 | /** |
@@ -38,8 +37,7 @@ discard block |
||
| 38 | 37 | $level = $this->getLevel($level); |
| 39 | 38 | |
| 40 | 39 | return get_class($this) == config('laravel-acl.level') ? |
| 41 | - $this->rank <= $level->rank : |
|
| 42 | - $this->level->rank <= $level->rank; |
|
| 40 | + $this->rank <= $level->rank : $this->level->rank <= $level->rank; |
|
| 43 | 41 | } |
| 44 | 42 | |
| 45 | 43 | /** |
@@ -133,7 +131,7 @@ discard block |
||
| 133 | 131 | return \Cache::remember( |
| 134 | 132 | 'laravel-acl.getAllPermissionsFor' . $model . '_' . $this->id, |
| 135 | 133 | config('laravel-acl.cacheMinutes'), |
| 136 | - function () { |
|
| 134 | + function() { |
|
| 137 | 135 | return $this->cacheGetAllPermissions(); |
| 138 | 136 | } |
| 139 | 137 | ); |
@@ -155,7 +153,7 @@ discard block |
||
| 155 | 153 | return \Cache::remember( |
| 156 | 154 | 'laravel-acl.getInheritedPermissionsFor' . $model . '_' . $this->id, |
| 157 | 155 | config('laravel-acl.cacheMinutes'), |
| 158 | - function () { |
|
| 156 | + function() { |
|
| 159 | 157 | return $this->cacheGetInheritedPermissions(); |
| 160 | 158 | } |
| 161 | 159 | ); |
@@ -177,7 +175,7 @@ discard block |
||
| 177 | 175 | return \Cache::remember( |
| 178 | 176 | 'laravel-acl.getAvailablePermissionsFor' . $model . '_' . $this->id, |
| 179 | 177 | config('laravel-acl.cacheMinutes'), |
| 180 | - function () { |
|
| 178 | + function() { |
|
| 181 | 179 | return $this->cacheGetAvailablePermissions(); |
| 182 | 180 | } |
| 183 | 181 | ); |
@@ -200,7 +198,7 @@ discard block |
||
| 200 | 198 | return \Cache::remember( |
| 201 | 199 | 'laravel-acl.hasPermissionTo_' . $model . '_' . $this->id . '_Permission_' . $permission, |
| 202 | 200 | config('laravel-acl.cacheMinutes'), |
| 203 | - function () use ($permission) { |
|
| 201 | + function() use ($permission) { |
|
| 204 | 202 | return $this->cacheHasPermissionTo($permission); |
| 205 | 203 | } |
| 206 | 204 | ); |
@@ -217,8 +215,7 @@ discard block |
||
| 217 | 215 | public function isLowerThan($other) |
| 218 | 216 | { |
| 219 | 217 | return get_class($this) == config('laravel-acl.user') ? |
| 220 | - $this->level->rank > $other->level->rank : |
|
| 221 | - $this->rank > $other->rank; |
|
| 218 | + $this->level->rank > $other->level->rank : $this->rank > $other->rank; |
|
| 222 | 219 | } |
| 223 | 220 | |
| 224 | 221 | /** |
@@ -232,8 +229,7 @@ discard block |
||
| 232 | 229 | public function isHigherThan($other) |
| 233 | 230 | { |
| 234 | 231 | return get_class($this) == config('laravel-acl.user') ? |
| 235 | - $this->level->rank < $other->level->rank : |
|
| 236 | - $this->rank < $other->rank; |
|
| 232 | + $this->level->rank < $other->level->rank : $this->rank < $other->rank; |
|
| 237 | 233 | } |
| 238 | 234 | |
| 239 | 235 | /** |
@@ -247,8 +243,7 @@ discard block |
||
| 247 | 243 | public function isEqualTo($other) |
| 248 | 244 | { |
| 249 | 245 | return get_class($this) == config('laravel-acl.user') ? |
| 250 | - $this->level->rank == $other->level->rank : |
|
| 251 | - $this->rank == $other->rank; |
|
| 246 | + $this->level->rank == $other->level->rank : $this->rank == $other->rank; |
|
| 252 | 247 | } |
| 253 | 248 | |
| 254 | 249 | |
@@ -267,14 +262,13 @@ discard block |
||
| 267 | 262 | protected function cacheGetAllPermissions() |
| 268 | 263 | { |
| 269 | 264 | $rank = get_class($this) == config('laravel-acl.level') ? |
| 270 | - $this->rank : |
|
| 271 | - $this->level->rank; |
|
| 265 | + $this->rank : $this->level->rank; |
|
| 272 | 266 | |
| 273 | 267 | $levels = config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get(); |
| 274 | 268 | |
| 275 | 269 | $allPerms = new Collection(); |
| 276 | 270 | |
| 277 | - $levels->each(function ($level, $key) use (&$allPerms) { |
|
| 271 | + $levels->each(function($level, $key) use (&$allPerms) { |
|
| 278 | 272 | $allPerms = $allPerms->merge($level->permissions); |
| 279 | 273 | }); |
| 280 | 274 | |
@@ -290,16 +284,14 @@ discard block |
||
| 290 | 284 | protected function cacheGetInheritedPermissions() |
| 291 | 285 | { |
| 292 | 286 | $rank = get_class($this) == config('laravel-acl.level') ? |
| 293 | - $this->rank : |
|
| 294 | - $this->level->rank; |
|
| 287 | + $this->rank : $this->level->rank; |
|
| 295 | 288 | |
| 296 | 289 | $levels = get_class($this) == config('laravel-acl.user') ? |
| 297 | - config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : |
|
| 298 | - config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
| 290 | + config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
| 299 | 291 | |
| 300 | 292 | $inheritedPerms = new Collection(); |
| 301 | 293 | |
| 302 | - $levels->each(function ($level, $key) use (&$inheritedPerms) { |
|
| 294 | + $levels->each(function($level, $key) use (&$inheritedPerms) { |
|
| 303 | 295 | $inheritedPerms = $inheritedPerms->merge($level->permissions->load('level')); |
| 304 | 296 | }); |
| 305 | 297 | |
@@ -396,8 +388,7 @@ discard block |
||
| 396 | 388 | $permissionsObjects[$permission->id] = ['negated' => true]; |
| 397 | 389 | } else { |
| 398 | 390 | $model == 'User' ? |
| 399 | - array_push($permissionsObjects, $permission->id) : |
|
| 400 | - array_push($permissionsObjects, $permission); |
|
| 391 | + array_push($permissionsObjects, $permission->id) : array_push($permissionsObjects, $permission); |
|
| 401 | 392 | } |
| 402 | 393 | } |
| 403 | 394 | |
@@ -433,7 +424,7 @@ discard block |
||
| 433 | 424 | $this->permissions()->detach($permissionObjects); |
| 434 | 425 | |
| 435 | 426 | if ($model == 'Level') { |
| 436 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
| 427 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
| 437 | 428 | return $permission->id; |
| 438 | 429 | }, $permissionObjects))->update(['level_id' => null]); |
| 439 | 430 | } |
@@ -454,7 +445,7 @@ discard block |
||
| 454 | 445 | if ($model == 'Level') { |
| 455 | 446 | $this->clearPermissions(); |
| 456 | 447 | |
| 457 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
| 448 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
| 458 | 449 | return $permission->id; |
| 459 | 450 | }, $permissionObjects)) |
| 460 | 451 | ->update(['level_id' => $this->id]); |
@@ -105,11 +105,13 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function clearPermissions() |
| 107 | 107 | { |
| 108 | - if (get_class($this) == config('laravel-acl.user')) |
|
| 109 | - $this->permissions()->detach(); |
|
| 108 | + if (get_class($this) == config('laravel-acl.user')) { |
|
| 109 | + $this->permissions()->detach(); |
|
| 110 | + } |
|
| 110 | 111 | |
| 111 | - if (get_class($this) == config('laravel-acl.level')) |
|
| 112 | - config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
| 112 | + if (get_class($this) == config('laravel-acl.level')) { |
|
| 113 | + config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
| 114 | + } |
|
| 113 | 115 | } |
| 114 | 116 | |
| 115 | 117 | |
@@ -413,11 +415,13 @@ discard block |
||
| 413 | 415 | */ |
| 414 | 416 | protected function addOrNegate($model, $permissionObjects, $action) |
| 415 | 417 | { |
| 416 | - if ($model == 'User') |
|
| 417 | - $this->permissions()->attach($permissionObjects); |
|
| 418 | + if ($model == 'User') { |
|
| 419 | + $this->permissions()->attach($permissionObjects); |
|
| 420 | + } |
|
| 418 | 421 | |
| 419 | - if ($model == 'Level') |
|
| 420 | - $this->permissions()->saveMany($permissionObjects); |
|
| 422 | + if ($model == 'Level') { |
|
| 423 | + $this->permissions()->saveMany($permissionObjects); |
|
| 424 | + } |
|
| 421 | 425 | } |
| 422 | 426 | |
| 423 | 427 | /** |
@@ -429,8 +433,9 @@ discard block |
||
| 429 | 433 | */ |
| 430 | 434 | protected function remove($model, $permissionObjects) |
| 431 | 435 | { |
| 432 | - if ($model == 'User') |
|
| 433 | - $this->permissions()->detach($permissionObjects); |
|
| 436 | + if ($model == 'User') { |
|
| 437 | + $this->permissions()->detach($permissionObjects); |
|
| 438 | + } |
|
| 434 | 439 | |
| 435 | 440 | if ($model == 'Level') { |
| 436 | 441 | config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
@@ -448,8 +453,9 @@ discard block |
||
| 448 | 453 | */ |
| 449 | 454 | protected function sync($model, $permissionObjects) |
| 450 | 455 | { |
| 451 | - if ($model == 'User') |
|
| 452 | - $this->permissions()->sync($permissionObjects); |
|
| 456 | + if ($model == 'User') { |
|
| 457 | + $this->permissions()->sync($permissionObjects); |
|
| 458 | + } |
|
| 453 | 459 | |
| 454 | 460 | if ($model == 'Level') { |
| 455 | 461 | $this->clearPermissions(); |
@@ -472,14 +478,17 @@ discard block |
||
| 472 | 478 | */ |
| 473 | 479 | protected function getPermission($permission) |
| 474 | 480 | { |
| 475 | - if (is_string($permission)) |
|
| 476 | - $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
| 481 | + if (is_string($permission)) { |
|
| 482 | + $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
| 483 | + } |
|
| 477 | 484 | |
| 478 | - if (is_int($permission)) |
|
| 479 | - $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
| 485 | + if (is_int($permission)) { |
|
| 486 | + $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
| 487 | + } |
|
| 480 | 488 | |
| 481 | - if (!$permission) |
|
| 482 | - throw new PermissionNotFoundException; |
|
| 489 | + if (!$permission) { |
|
| 490 | + throw new PermissionNotFoundException; |
|
| 491 | + } |
|
| 483 | 492 | |
| 484 | 493 | return $permission; |
| 485 | 494 | } |