@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public function removeFilterByID($id) |
289 | 289 | { |
290 | - $this->filters = array_filter($this->filters, function (AbstractFilter $filter) use ($id) { |
|
290 | + $this->filters = array_filter($this->filters, function(AbstractFilter $filter) use ($id) { |
|
291 | 291 | return $filter->getId() != $id; |
292 | 292 | }); |
293 | 293 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | { |
302 | 302 | $inputs = Arr::dot(request()->all()); |
303 | 303 | |
304 | - $inputs = array_filter($inputs, function ($input) { |
|
304 | + $inputs = array_filter($inputs, function($input) { |
|
305 | 305 | return $input !== '' && !is_null($input); |
306 | 306 | }); |
307 | 307 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
332 | - return tap(array_filter($conditions), function ($conditions) { |
|
332 | + return tap(array_filter($conditions), function($conditions) { |
|
333 | 333 | if (!empty($conditions)) { |
334 | 334 | $this->expand(); |
335 | 335 | } |
@@ -347,9 +347,9 @@ discard block |
||
347 | 347 | return $inputs; |
348 | 348 | } |
349 | 349 | |
350 | - $inputs = collect($inputs)->filter(function ($input, $key) { |
|
350 | + $inputs = collect($inputs)->filter(function($input, $key) { |
|
351 | 351 | return Str::startsWith($key, "{$this->name}_"); |
352 | - })->mapWithKeys(function ($val, $key) { |
|
352 | + })->mapWithKeys(function($val, $key) { |
|
353 | 353 | $key = str_replace("{$this->name}_", '', $key); |
354 | 354 | |
355 | 355 | return [$key => $val]; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | */ |
420 | 420 | public function scope($key, $label = '') |
421 | 421 | { |
422 | - return tap(new Scope($key, $label), function (Scope $scope) { |
|
422 | + return tap(new Scope($key, $label), function(Scope $scope) { |
|
423 | 423 | return $this->scopes->push($scope); |
424 | 424 | }); |
425 | 425 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | { |
454 | 454 | $key = request(Scope::QUERY_NAME); |
455 | 455 | |
456 | - return $this->scopes->first(function ($scope) use ($key) { |
|
456 | + return $this->scopes->first(function($scope) use ($key) { |
|
457 | 457 | return $scope->key == $key; |
458 | 458 | }); |
459 | 459 | } |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | |
579 | 579 | $columns->push($pageKey); |
580 | 580 | |
581 | - $groupNames = collect($this->filters)->filter(function ($filter) { |
|
581 | + $groupNames = collect($this->filters)->filter(function($filter) { |
|
582 | 582 | return $filter instanceof Filter\Group; |
583 | - })->map(function (AbstractFilter $filter) { |
|
583 | + })->map(function(AbstractFilter $filter) { |
|
584 | 584 | return "{$filter->getId()}_group"; |
585 | 585 | }); |
586 | 586 | |
@@ -672,8 +672,8 @@ discard block |
||
672 | 672 | public function bool(string $field_name, bool $is_int = false, ?string $label = null): void |
673 | 673 | { |
674 | 674 | if ($is_int) { |
675 | - $this->where(function ($query) use ($field_name) { |
|
676 | - $query->whereRaw('`'.$field_name.'` = '.((int)$this->input)); |
|
675 | + $this->where(function($query) use ($field_name) { |
|
676 | + $query->whereRaw('`'.$field_name.'` = '.((int) $this->input)); |
|
677 | 677 | }, $label ?? $field_name, $field_name)->radio([ |
678 | 678 | '' => 'All', |
679 | 679 | 1 => 'Yes', |
@@ -122,12 +122,14 @@ discard block |
||
122 | 122 | if (!empty($periods)) { |
123 | 123 | $res = []; |
124 | 124 | foreach ($periods as $period) { |
125 | - if (array_key_exists($period, self::PERIODS)) |
|
126 | - $res[] = $period; |
|
125 | + if (array_key_exists($period, self::PERIODS)) { |
|
126 | + $res[] = $period; |
|
127 | + } |
|
127 | 128 | } |
128 | 129 | |
129 | - if (!empty($res)) |
|
130 | - $this->periods = $res; |
|
130 | + if (!empty($res)) { |
|
131 | + $this->periods = $res; |
|
132 | + } |
|
131 | 133 | } |
132 | 134 | |
133 | 135 | return $this; |
@@ -140,8 +142,9 @@ discard block |
||
140 | 142 | public function condition($inputs) |
141 | 143 | { |
142 | 144 | $type = $inputs[$this->column]['type'] ?? $this->getDefault(); |
143 | - if ($this->ignore || !$type || !array_key_exists($type, self::PERIODS)) |
|
144 | - return; |
|
145 | + if ($this->ignore || !$type || !array_key_exists($type, self::PERIODS)) { |
|
146 | + return; |
|
147 | + } |
|
145 | 148 | |
146 | 149 | if ($type === self::CUSTOM_DATE || $type === self::CUSTOM_DATETIME) { |
147 | 150 | return $this->handleCustomDate($inputs, $type); |
@@ -180,20 +183,23 @@ discard block |
||
180 | 183 | protected function handleCustomDate(array $inputs, string $type): mixed |
181 | 184 | { |
182 | 185 | $value = $inputs[$this->column][$type] ?? null; |
183 | - if (!$value) |
|
184 | - return null; |
|
186 | + if (!$value) { |
|
187 | + return null; |
|
188 | + } |
|
185 | 189 | |
186 | 190 | $format = self::CUSTOM_FORMATS[$type]; |
187 | 191 | foreach ($value as $key => $row) { |
188 | 192 | $date = \DateTime::createFromFormat($format, $row); |
189 | - if (!$date) |
|
190 | - return null; |
|
193 | + if (!$date) { |
|
194 | + return null; |
|
195 | + } |
|
191 | 196 | |
192 | 197 | $value[$key] = $date->format($format); |
193 | 198 | } |
194 | 199 | |
195 | - if ($type === self::CUSTOM_DATE && !empty($value['end'])) |
|
196 | - $value['end'] .= ' 23:59:59'; |
|
200 | + if ($type === self::CUSTOM_DATE && !empty($value['end'])) { |
|
201 | + $value['end'] .= ' 23:59:59'; |
|
202 | + } |
|
197 | 203 | |
198 | 204 | return match (true) { |
199 | 205 | !isset($value['start']) => $this->buildCondition($this->column, '<=', $value['end']), |
@@ -286,8 +292,9 @@ discard block |
||
286 | 292 | public static function isNotFilled(string $column): bool |
287 | 293 | { |
288 | 294 | $request = request()->query($column); |
289 | - if (!$request) |
|
290 | - return true; |
|
295 | + if (!$request) { |
|
296 | + return true; |
|
297 | + } |
|
291 | 298 | |
292 | 299 | $type = $request['type'] ?? null; |
293 | 300 |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | */ |
437 | 437 | public function json(int $max_width = 600) |
438 | 438 | { |
439 | - return $this->display(function ($val) { |
|
439 | + return $this->display(function($val) { |
|
440 | 440 | $json = json_decode($val, true); |
441 | 441 | if (!$json || !is_array($json)) |
442 | 442 | return e($val); |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | */ |
470 | 470 | public function money(int $decimals = 2) |
471 | 471 | { |
472 | - return $this->display(function ($val) use ($decimals) { |
|
473 | - return is_null($val) ? '' : number_format((float)$val, $decimals); |
|
472 | + return $this->display(function($val) use ($decimals) { |
|
473 | + return is_null($val) ? '' : number_format((float) $val, $decimals); |
|
474 | 474 | }); |
475 | 475 | } |
476 | 476 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | $column = $this; |
490 | 490 | |
491 | - return $this->display(function ($value) use ($grid, $column, $abstract, $arguments) { |
|
491 | + return $this->display(function($value) use ($grid, $column, $abstract, $arguments) { |
|
492 | 492 | /** @var AbstractDisplayer $displayer */ |
493 | 493 | $displayer = new $abstract($value, $grid, $column, $this); |
494 | 494 | |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | |
538 | 538 | $grid = $this->grid; |
539 | 539 | |
540 | - return $this->display(function ($_, $column) use ($action, $grid) { |
|
540 | + return $this->display(function($_, $column) use ($action, $grid) { |
|
541 | 541 | /** @var RowAction $action */ |
542 | 542 | $action = new $action(); |
543 | 543 | |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $grid = $this->grid; |
666 | 666 | $column = $this; |
667 | 667 | |
668 | - $this->display(function ($value) use ($grid, $column, $class) { |
|
668 | + $this->display(function($value) use ($grid, $column, $class) { |
|
669 | 669 | /** @var AbstractDisplayer $definition */ |
670 | 670 | $definition = new $class($value, $grid, $column, $this); |
671 | 671 | |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | protected function htmlEntityEncode($item) |
684 | 684 | { |
685 | 685 | if (is_array($item)) { |
686 | - array_walk_recursive($item, function (&$value) { |
|
686 | + array_walk_recursive($item, function(&$value) { |
|
687 | 687 | $value = htmlentities($value ?? ''); |
688 | 688 | }); |
689 | 689 | } else { |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | */ |
721 | 721 | protected function callSupportDisplayer($abstract, $arguments) |
722 | 722 | { |
723 | - return $this->display(function ($value) use ($abstract, $arguments) { |
|
723 | + return $this->display(function($value) use ($abstract, $arguments) { |
|
724 | 724 | if (is_array($value) || $value instanceof Arrayable) { |
725 | 725 | return call_user_func_array([collect($value), $abstract], $arguments); |
726 | 726 | } |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | protected function callBuiltinDisplayer($abstract, $arguments) |
745 | 745 | { |
746 | 746 | if ($abstract instanceof Closure) { |
747 | - return $this->display(function ($value) use ($abstract, $arguments) { |
|
747 | + return $this->display(function($value) use ($abstract, $arguments) { |
|
748 | 748 | return $abstract->call($this, ...array_merge([$value], $arguments)); |
749 | 749 | }); |
750 | 750 | } |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | $grid = $this->grid; |
754 | 754 | $column = $this; |
755 | 755 | |
756 | - return $this->display(function ($value) use ($abstract, $grid, $column, $arguments) { |
|
756 | + return $this->display(function($value) use ($abstract, $grid, $column, $arguments) { |
|
757 | 757 | /** @var AbstractDisplayer $displayer */ |
758 | 758 | $displayer = new $abstract($value, $grid, $column, $this); |
759 | 759 |
@@ -438,8 +438,9 @@ |
||
438 | 438 | { |
439 | 439 | return $this->display(function ($val) { |
440 | 440 | $json = json_decode($val, true); |
441 | - if (!$json || !is_array($json)) |
|
442 | - return e($val); |
|
441 | + if (!$json || !is_array($json)) { |
|
442 | + return e($val); |
|
443 | + } |
|
443 | 444 | return '<pre>'.e(json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)).'</pre>'; |
444 | 445 | })->style(implode(';', [ |
445 | 446 | 'max-width: '.$max_width.'px', |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | |
91 | 91 | $this->compatibleBlade(); |
92 | 92 | |
93 | - Blade::directive('box', function ($title) { |
|
93 | + Blade::directive('box', function($title) { |
|
94 | 94 | return "<?php \$box = new \Encore\Admin\Widgets\Box({$title}, '"; |
95 | 95 | }); |
96 | 96 | |
97 | - Blade::directive('endbox', function ($expression) { |
|
97 | + Blade::directive('endbox', function($expression) { |
|
98 | 98 | return "'); echo \$box->render(); ?>"; |
99 | 99 | }); |
100 | 100 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function macroRouter() |
155 | 155 | { |
156 | - Router::macro('content', function ($uri, $content, $options = []) { |
|
157 | - return $this->match(['GET', 'HEAD'], $uri, function (Content $layout) use ($content, $options) { |
|
156 | + Router::macro('content', function($uri, $content, $options = []) { |
|
157 | + return $this->match(['GET', 'HEAD'], $uri, function(Content $layout) use ($content, $options) { |
|
158 | 158 | return $layout |
159 | 159 | ->title(Arr::get($options, 'title', ' ')) |
160 | 160 | ->description(Arr::get($options, 'desc', ' ')) |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | }); |
163 | 163 | }); |
164 | 164 | |
165 | - Router::macro('component', function ($uri, $component, $data = [], $options = []) { |
|
166 | - return $this->match(['GET', 'HEAD'], $uri, function (Content $layout) use ($component, $data, $options) { |
|
165 | + Router::macro('component', function($uri, $component, $data = [], $options = []) { |
|
166 | + return $this->match(['GET', 'HEAD'], $uri, function(Content $layout) use ($component, $data, $options) { |
|
167 | 167 | return $layout |
168 | 168 | ->title(Arr::get($options, 'title', ' ')) |
169 | 169 | ->description(Arr::get($options, 'desc', ' ')) |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function bool() |
191 | 191 | { |
192 | - return $this->as(function ($val) { |
|
192 | + return $this->as(function($val) { |
|
193 | 193 | return is_null($val) ? 'Undefined' : ($val ? 'Yes' : 'No'); |
194 | 194 | }); |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function check() |
203 | 203 | { |
204 | - return $this->unescape()->as(function ($val) { |
|
204 | + return $this->unescape()->as(function($val) { |
|
205 | 205 | return is_null($val) ? '<i class="fa fa-check text-gray"></i>' : ($val ? '<i class="fa fa-check text-green"></i>' : '<i class="fa fa-close text-red"></i>'); |
206 | 206 | }); |
207 | 207 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | public static function _jsonParse() |
245 | 245 | { |
246 | - return function ($val) { |
|
246 | + return function($val) { |
|
247 | 247 | $json = json_decode($val, true); |
248 | 248 | if (!$json || !is_array($json)) |
249 | 249 | return e($val); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function using(array $values, $default = null) |
274 | 274 | { |
275 | - return $this->as(function ($value) use ($values, $default) { |
|
275 | + return $this->as(function($value) use ($values, $default) { |
|
276 | 276 | if (is_null($value)) { |
277 | 277 | return $default; |
278 | 278 | } |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function image($server = '', $width = 200, $height = 200) |
294 | 294 | { |
295 | - return $this->unescape()->as(function ($images) use ($server, $width, $height) { |
|
296 | - return collect($images)->map(function ($path) use ($server, $width, $height) { |
|
295 | + return $this->unescape()->as(function($images) use ($server, $width, $height) { |
|
296 | + return collect($images)->map(function($path) use ($server, $width, $height) { |
|
297 | 297 | if (empty($path)) { |
298 | 298 | return ''; |
299 | 299 | } |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | */ |
329 | 329 | public function carousel($width = 300, $height = 200, $server = '') |
330 | 330 | { |
331 | - return $this->unescape()->as(function ($images) use ($server, $width, $height) { |
|
332 | - $items = collect($images)->map(function ($path) use ($server, $width, $height) { |
|
331 | + return $this->unescape()->as(function($images) use ($server, $width, $height) { |
|
332 | + $items = collect($images)->map(function($path) use ($server, $width, $height) { |
|
333 | 333 | if (empty($path)) { |
334 | 334 | return ''; |
335 | 335 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | { |
370 | 370 | $field = $this; |
371 | 371 | |
372 | - return $this->unescape()->as(function ($path) use ($server, $download, $field) { |
|
372 | + return $this->unescape()->as(function($path) use ($server, $download, $field) { |
|
373 | 373 | $name = basename($path); |
374 | 374 | |
375 | 375 | $field->border = false; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function link($href = '', $target = '_blank') |
425 | 425 | { |
426 | - return $this->unescape()->as(function ($link) use ($href, $target) { |
|
426 | + return $this->unescape()->as(function($link) use ($href, $target) { |
|
427 | 427 | $href = $href ?: $link; |
428 | 428 | |
429 | 429 | return "<a href='$href' target='{$target}'>{$link}</a>"; |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | */ |
440 | 440 | public function label($style = 'success') |
441 | 441 | { |
442 | - return $this->unescape()->as(function ($value) use ($style) { |
|
442 | + return $this->unescape()->as(function($value) use ($style) { |
|
443 | 443 | if ($value instanceof Arrayable) { |
444 | 444 | $value = $value->toArray(); |
445 | 445 | } |
446 | 446 | |
447 | - return collect((array) $value)->map(function ($name) use ($style) { |
|
447 | + return collect((array) $value)->map(function($name) use ($style) { |
|
448 | 448 | return "<span class='label label-{$style}'>$name</span>"; |
449 | 449 | })->implode(' '); |
450 | 450 | }); |
@@ -459,12 +459,12 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function badge($style = 'blue') |
461 | 461 | { |
462 | - return $this->unescape()->as(function ($value) use ($style) { |
|
462 | + return $this->unescape()->as(function($value) use ($style) { |
|
463 | 463 | if ($value instanceof Arrayable) { |
464 | 464 | $value = $value->toArray(); |
465 | 465 | } |
466 | 466 | |
467 | - return collect((array) $value)->map(function ($name) use ($style) { |
|
467 | + return collect((array) $value)->map(function($name) use ($style) { |
|
468 | 468 | return "<span class='badge bg-{$style}'>$name</span>"; |
469 | 469 | })->implode(' '); |
470 | 470 | }); |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function number($decimals = 0, $decimal_seperator = '.', $thousands_seperator = ',') |
483 | 483 | { |
484 | - return $this->unescape()->as(function ($value) use ($decimals, $decimal_seperator, $thousands_seperator) { |
|
484 | + return $this->unescape()->as(function($value) use ($decimals, $decimal_seperator, $thousands_seperator) { |
|
485 | 485 | return number_format($value, $decimals, $decimal_seperator, $thousands_seperator); |
486 | 486 | }); |
487 | 487 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | { |
496 | 496 | $field = $this; |
497 | 497 | |
498 | - return $this->unescape()->as(function ($value) use ($field) { |
|
498 | + return $this->unescape()->as(function($value) use ($field) { |
|
499 | 499 | if (is_string($value)) { |
500 | 500 | $content = json_decode($value, true); |
501 | 501 | } else { |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | */ |
520 | 520 | public function filesize() |
521 | 521 | { |
522 | - return $this->as(function ($value) { |
|
522 | + return $this->as(function($value) { |
|
523 | 523 | return file_size($value); |
524 | 524 | }); |
525 | 525 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | |
678 | 678 | $field = $this; |
679 | 679 | |
680 | - return $this->as(function ($value) use ($extend, $field, $arguments) { |
|
680 | + return $this->as(function($value) use ($extend, $field, $arguments) { |
|
681 | 681 | if (!$extend->border) { |
682 | 682 | $field->border = false; |
683 | 683 | } |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | public function render() |
737 | 737 | { |
738 | 738 | if ($this->showAs->isNotEmpty()) { |
739 | - $this->showAs->each(function ($callable) { |
|
739 | + $this->showAs->each(function($callable) { |
|
740 | 740 | $this->value = $callable->call( |
741 | 741 | $this->parent->getModel(), |
742 | 742 | $this->value |
@@ -245,8 +245,9 @@ |
||
245 | 245 | { |
246 | 246 | return function ($val) { |
247 | 247 | $json = json_decode($val, true); |
248 | - if (!$json || !is_array($json)) |
|
249 | - return e($val); |
|
248 | + if (!$json || !is_array($json)) { |
|
249 | + return e($val); |
|
250 | + } |
|
250 | 251 | $res = '<pre>'; |
251 | 252 | foreach ($json as $lang => $text) { |
252 | 253 | if (is_string($text) || is_numeric($text)) { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function json(): self |
44 | 44 | { |
45 | - $this->customFormat = function ($val) { |
|
45 | + $this->customFormat = function($val) { |
|
46 | 46 | $json = json_decode($val); |
47 | 47 | return !$val || json_last_error() !== JSON_ERROR_NONE |
48 | 48 | ? $val |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $this->value = json_encode($this->value, JSON_PRETTY_PRINT); |
66 | 66 | } |
67 | 67 | |
68 | - $this->mountPicker(function ($btn) { |
|
68 | + $this->mountPicker(function($btn) { |
|
69 | 69 | $this->addPickBtn($btn); |
70 | 70 | }); |
71 | 71 |
@@ -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 | } |
@@ -43,8 +43,9 @@ |
||
43 | 43 | public static function clearCache(): void |
44 | 44 | { |
45 | 45 | $cache = config('admin.cache')['enable'] ? Cache::store(config('admin.cache')['store']) : null; |
46 | - if (!$cache) |
|
47 | - return; |
|
46 | + if (!$cache) { |
|
47 | + return; |
|
48 | + } |
|
48 | 49 | |
49 | 50 | $cache->delete('admin_menu'); |
50 | 51 | $cache->delete('admin_role_permissions'); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | class AuthListener |
13 | 13 | { |
14 | - public function handle(Authenticated|Failed $event): void |
|
14 | + public function handle(Authenticated | Failed $event): void |
|
15 | 15 | { |
16 | 16 | if ($event instanceof Authenticated && !empty($event->user->is_blocked)) { |
17 | 17 | $this->logout($event->user, true); |
@@ -42,8 +42,9 @@ |
||
42 | 42 | { |
43 | 43 | $user->remember_token = null; |
44 | 44 | $user->google2fa_remember_token = null; |
45 | - if ($change_password) |
|
46 | - $user->password = Hash::make(Str::random(32)); |
|
45 | + if ($change_password) { |
|
46 | + $user->password = Hash::make(Str::random(32)); |
|
47 | + } |
|
47 | 48 | $user->save(); |
48 | 49 | |
49 | 50 | Admin::guard()->logout(); |