diff --git a/src/Traits/WithCheckbox.php b/src/Traits/WithCheckbox.php index ef9b3a62..f2faf32b 100644 --- a/src/Traits/WithCheckbox.php +++ b/src/Traits/WithCheckbox.php @@ -37,22 +37,24 @@ public function selectCheckboxAll(): void $actionRulesClass = resolve(ActionRules::class); /** @phpstan-ignore-next-line */ - collect($data->items())->each(function (array|Model|\stdClass $model) use ($actionRulesClass) { - $rules = $actionRulesClass->recoverFromAction('pg:checkbox', $model); - - if (isset($rules['hide']) || isset($rules['disable'])) { - return; - } - $value = $model->{$this->checkboxAttribute}; - - if (!in_array($value, $this->checkboxValues)) { - $this->checkboxValues[] = (string) $value; - - $this->dispatchBrowserEvent('pgBulkActions::addMore', [ - 'value' => $value, - 'tableName' => $this->tableName, - ]); - } - }); + if ($data->isNotEmpty()) { + collect($data->items())->each(function (array|Model|\stdClass $model) use ($actionRulesClass) { + $rules = $actionRulesClass->recoverFromAction('pg:checkbox', $model); + + if (isset($rules['hide']) || isset($rules['disable'])) { + return; + } + $value = $model->{$this->checkboxAttribute}; + + if (!in_array($value, $this->checkboxValues)) { + $this->checkboxValues[] = (string) $value; + + $this->dispatchBrowserEvent('pgBulkActions::addMore', [ + 'value' => $value, + 'tableName' => $this->tableName, + ]); + } + }); + } } }