@@ -112,7 +112,7 @@ |
||
| 112 | 112 | */ |
| 113 | 113 | protected static function bootHasPermissions() |
| 114 | 114 | { |
| 115 | - static::deleting(function ($model) { |
|
| 115 | + static::deleting(function($model) { |
|
| 116 | 116 | $model->roles()->detach(); |
| 117 | 117 | |
| 118 | 118 | $model->permissions()->detach(); |
@@ -10,15 +10,17 @@ discard block |
||
| 10 | 10 | private function getRolePermissions(): array |
| 11 | 11 | { |
| 12 | 12 | static $role_permissions = []; |
| 13 | - if (!empty($role_permissions)) |
|
| 14 | - return $role_permissions; |
|
| 13 | + if (!empty($role_permissions)) { |
|
| 14 | + return $role_permissions; |
|
| 15 | + } |
|
| 15 | 16 | |
| 16 | 17 | $cache = config('admin.cache')['enable'] ? Cache::store(config('admin.cache')['store']) : null; |
| 17 | 18 | $cache_key = 'admin_role_permissions'; |
| 18 | 19 | if ($cache) { |
| 19 | 20 | $role_permissions = $cache->get($cache_key) ?? []; |
| 20 | - if (!empty($role_permissions)) |
|
| 21 | - return $role_permissions; |
|
| 21 | + if (!empty($role_permissions)) { |
|
| 22 | + return $role_permissions; |
|
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | |
| 24 | 26 | $roles = Role::with('permissions')->get(); |
@@ -26,8 +28,9 @@ discard block |
||
| 26 | 28 | $role_permissions[$role->id] = $role->permissions->toArray(); |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | - if ($cache) |
|
| 30 | - $cache->put($cache_key, $role_permissions, 600); |
|
| 31 | + if ($cache) { |
|
| 32 | + $cache->put($cache_key, $role_permissions, 600); |
|
| 33 | + } |
|
| 31 | 34 | |
| 32 | 35 | return $role_permissions; |
| 33 | 36 | } |
@@ -35,15 +38,17 @@ discard block |
||
| 35 | 38 | private function getUserPermissions(): array |
| 36 | 39 | { |
| 37 | 40 | static $user_permissions = []; |
| 38 | - if (!empty($user_permissions[$this->id])) |
|
| 39 | - return $user_permissions[$this->id]; |
|
| 41 | + if (!empty($user_permissions[$this->id])) { |
|
| 42 | + return $user_permissions[$this->id]; |
|
| 43 | + } |
|
| 40 | 44 | |
| 41 | 45 | $cache = config('admin.cache')['enable'] ? Cache::store(config('admin.cache')['store']) : null; |
| 42 | 46 | $cache_key = 'admin_user_permissions'; |
| 43 | 47 | if ($cache) { |
| 44 | 48 | $user_permissions = $cache->get($cache_key) ?? []; |
| 45 | - if (!empty($user_permissions[$this->id])) |
|
| 46 | - return $user_permissions[$this->id]; |
|
| 49 | + if (!empty($user_permissions[$this->id])) { |
|
| 50 | + return $user_permissions[$this->id]; |
|
| 51 | + } |
|
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | $user_permissions[$this->id] = [ |
@@ -51,8 +56,9 @@ discard block |
||
| 51 | 56 | 'permissions' => $this->permissions->toArray(), |
| 52 | 57 | ]; |
| 53 | 58 | |
| 54 | - if ($cache) |
|
| 55 | - $cache->put($cache_key, $user_permissions, 600); |
|
| 59 | + if ($cache) { |
|
| 60 | + $cache->put($cache_key, $user_permissions, 600); |
|
| 61 | + } |
|
| 56 | 62 | |
| 57 | 63 | return $user_permissions[$this->id]; |
| 58 | 64 | } |
@@ -111,16 +117,18 @@ discard block |
||
| 111 | 117 | 'user_permissions' => array_column($this->getUserPermissions()['permissions'], 'slug'), |
| 112 | 118 | ]; |
| 113 | 119 | } |
| 114 | - if (in_array($ability, $can[$this->id]['user_permissions'])) |
|
| 115 | - return true; |
|
| 120 | + if (in_array($ability, $can[$this->id]['user_permissions'])) { |
|
| 121 | + return true; |
|
| 122 | + } |
|
| 116 | 123 | |
| 117 | 124 | if (!isset($can[$this->id]['role_permissions'])) { |
| 118 | 125 | $permissions = []; |
| 119 | 126 | $role_ids = array_column($this->getUserPermissions()['roles'], 'id'); |
| 120 | 127 | $role_permissions = $this->getRolePermissions(); |
| 121 | 128 | foreach ($role_ids as $role_id) { |
| 122 | - if (!empty($role_permissions[$role_id])) |
|
| 123 | - $permissions = array_merge($permissions, $role_permissions[$role_id]); |
|
| 129 | + if (!empty($role_permissions[$role_id])) { |
|
| 130 | + $permissions = array_merge($permissions, $role_permissions[$role_id]); |
|
| 131 | + } |
|
| 124 | 132 | } |
| 125 | 133 | $can[$this->id]['role_permissions'] = array_column($permissions, 'slug'); |
| 126 | 134 | } |
@@ -148,8 +156,9 @@ discard block |
||
| 148 | 156 | public function isAdministrator(): bool |
| 149 | 157 | { |
| 150 | 158 | static $is_administrator = []; |
| 151 | - if (!isset($is_administrator[$this->id])) |
|
| 152 | - $is_administrator[$this->id] = $this->isRole('administrator'); |
|
| 159 | + if (!isset($is_administrator[$this->id])) { |
|
| 160 | + $is_administrator[$this->id] = $this->isRole('administrator'); |
|
| 161 | + } |
|
| 153 | 162 | |
| 154 | 163 | return $is_administrator[$this->id]; |
| 155 | 164 | } |
@@ -181,8 +190,9 @@ discard block |
||
| 181 | 190 | private function getUserRoles(): array |
| 182 | 191 | { |
| 183 | 192 | static $user_roles = []; |
| 184 | - if (!isset($user_roles[$this->id])) |
|
| 185 | - $user_roles[$this->id] = array_column($this->getUserPermissions()['roles'], 'slug'); |
|
| 193 | + if (!isset($user_roles[$this->id])) { |
|
| 194 | + $user_roles[$this->id] = array_column($this->getUserPermissions()['roles'], 'slug'); |
|
| 195 | + } |
|
| 186 | 196 | |
| 187 | 197 | return $user_roles[$this->id]; |
| 188 | 198 | } |
@@ -475,7 +475,7 @@ |
||
| 475 | 475 | $relation = substr($this->column, 0, strrpos($this->column, '.')); |
| 476 | 476 | $args[0] = last(explode('.', $this->column)); |
| 477 | 477 | |
| 478 | - return ['whereHas' => [$relation, function ($relation) use ($args) { |
|
| 478 | + return ['whereHas' => [$relation, function($relation) use ($args) { |
|
| 479 | 479 | call_user_func_array([$relation, $this->query], $args); |
| 480 | 480 | }]]; |
| 481 | 481 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | // for create or update |
| 156 | 156 | if ($this->pathColumn) { |
| 157 | - $targets = array_map(function ($target) { |
|
| 157 | + $targets = array_map(function($target) { |
|
| 158 | 158 | return [$this->pathColumn => $target]; |
| 159 | 159 | }, $targets); |
| 160 | 160 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | $this->name = $this->getStoreName($file); |
| 187 | 187 | |
| 188 | - return tap($this->upload($file), function () { |
|
| 188 | + return tap($this->upload($file), function() { |
|
| 189 | 189 | $this->name = null; |
| 190 | 190 | }); |
| 191 | 191 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | ]; |
| 30 | 30 | |
| 31 | 31 | try { |
| 32 | - DB::transaction(function () use ($model) { |
|
| 32 | + DB::transaction(function() use ($model) { |
|
| 33 | 33 | $model->delete(); |
| 34 | 34 | }); |
| 35 | 35 | } catch (\Exception $exception) { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | $this->overwriteExistingField($name); |
| 228 | 228 | |
| 229 | - return tap($field, function ($field) { |
|
| 229 | + return tap($field, function($field) { |
|
| 230 | 230 | $this->fields->push($field); |
| 231 | 231 | }); |
| 232 | 232 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | $this->overwriteExistingRelation($name); |
| 250 | 250 | |
| 251 | - return tap($relation, function ($relation) { |
|
| 251 | + return tap($relation, function($relation) { |
|
| 252 | 252 | $this->relations->push($relation); |
| 253 | 253 | }); |
| 254 | 254 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | $this->fields = $this->fields->filter( |
| 268 | - function (Field $field) use ($name) { |
|
| 268 | + function(Field $field) use ($name) { |
|
| 269 | 269 | return $field->getName() != $name; |
| 270 | 270 | } |
| 271 | 271 | ); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $this->relations = $this->relations->filter( |
| 286 | - function (Relation $relation) use ($name) { |
|
| 286 | + function(Relation $relation) use ($name) { |
|
| 287 | 287 | return $relation->getName() != $name; |
| 288 | 288 | } |
| 289 | 289 | ); |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | public function setWidth($fieldWidth = 8, $labelWidth = 2) |
| 342 | 342 | { |
| 343 | - collect($this->fields)->each(function ($field) use ($fieldWidth, $labelWidth) { |
|
| 343 | + collect($this->fields)->each(function($field) use ($fieldWidth, $labelWidth) { |
|
| 344 | 344 | $field->setWidth($fieldWidth, $labelWidth); |
| 345 | 345 | }); |
| 346 | 346 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $this->disablePagination(); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - $this->tools(function (Tools $tools) { |
|
| 89 | + $this->tools(function(Tools $tools) { |
|
| 90 | 90 | $tools->append(new Grid\Selectable\BrowserBtn()); |
| 91 | 91 | }); |
| 92 | 92 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $hide = $hide ? 'hide' : ''; |
| 99 | 99 | $key = $this->key; |
| 100 | 100 | |
| 101 | - $this->column('__remove__', ' ')->display(function () use ($hide, $key) { |
|
| 101 | + $this->column('__remove__', ' ')->display(function() use ($hide, $key) { |
|
| 102 | 102 | return <<<BTN |
| 103 | 103 | <a href="javascript:void(0);" class="grid-row-remove {$hide}" data-key="{$this->getAttribute($key)}"> |
| 104 | 104 | <i class="fa fa-trash"></i> |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | return collect(Arr::dot($from)) |
| 54 | 54 | ->keys() |
| 55 | - ->reject(function ($key) use ($to) { |
|
| 55 | + ->reject(function($key) use ($to) { |
|
| 56 | 56 | return Arr::has($to, $key); |
| 57 | 57 | }); |
| 58 | 58 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->line(''); |
| 67 | 67 | $this->comment("{$title}:"); |
| 68 | 68 | |
| 69 | - $diff->each(function ($key) use ($error) { |
|
| 69 | + $diff->each(function($key) use ($error) { |
|
| 70 | 70 | if ($error) { |
| 71 | 71 | $this->error(" {$key}"); |
| 72 | 72 | } else { |
@@ -125,7 +125,7 @@ |
||
| 125 | 125 | $value = explode($this->separator, $value); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - return collect(Arr::wrap($value))->map(function ($item) use ($field) { |
|
| 128 | + return collect(Arr::wrap($value))->map(function($item) use ($field) { |
|
| 129 | 129 | return [ |
| 130 | 130 | 'url' => $this->field->objectUrl($item), |
| 131 | 131 | 'value' => $item, |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | */ |
| 103 | 103 | protected function addActionScripts() |
| 104 | 104 | { |
| 105 | - $this->actions->each(function ($action) { |
|
| 105 | + $this->actions->each(function($action) { |
|
| 106 | 106 | $action->setGrid($this->grid); |
| 107 | 107 | |
| 108 | 108 | if (method_exists($action, 'script')) { |