From 84a049e165eaf699bbd78e2bb8c44bbd8c9a57db Mon Sep 17 00:00:00 2001 From: abhaypithadiya Date: Wed, 20 Sep 2023 18:35:46 +0530 Subject: [PATCH] - Resolved Checkbox All Errror when Collection is empty. --- src/Traits/WithCheckbox.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) 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, + ]); + } + }); + } } }