diff --git a/src/Traits/WithCheckbox.php b/src/Traits/WithCheckbox.php index 7594b310..79c9aae9 100644 --- a/src/Traits/WithCheckbox.php +++ b/src/Traits/WithCheckbox.php @@ -43,23 +43,25 @@ public function selectCheckboxAll(): void $actionRulesClass = resolve(RulesController::class); /** @phpstan-ignore-next-line */ - collect($data->items())->each(function (array|Model|\stdClass $model) use ($actionRulesClass) { - $rules = $actionRulesClass->recoverFromAction($model, 'pg:checkbox'); + if ($data->isNotEmpty()) { + collect($data->items())->each(function (array|Model|\stdClass $model) use ($actionRulesClass) { + $rules = $actionRulesClass->recoverFromAction($model, 'pg:checkbox'); - if (filled($rules['hide']) || filled($rules['disable'])) { - return; - } + if (filled($rules['hide']) || filled($rules['disable'])) { + return; + } - $value = $model->{$this->checkboxAttribute}; + $value = $model->{$this->checkboxAttribute}; - if (!in_array($value, $this->checkboxValues)) { - $this->checkboxValues[] = (string) $value; + if (!in_array($value, $this->checkboxValues)) { + $this->checkboxValues[] = (string) $value; - $this->dispatch('pgBulkActions::addMore', [ - 'value' => $value, - 'tableName' => $this->tableName, - ]); - } - }); + $this->dispatch('pgBulkActions::addMore', [ + 'value' => $value, + 'tableName' => $this->tableName, + ]); + } + }); + } } }