diff --git a/src/PowerGridComponent.php b/src/PowerGridComponent.php index 7dd5ac24..54248ec2 100644 --- a/src/PowerGridComponent.php +++ b/src/PowerGridComponent.php @@ -342,6 +342,31 @@ private function renderView(mixed $data): Application|Factory|View ]); } + private function resolveDetailRow(mixed $results): void + { + if (!isset($this->setUp['detail'])) { + return; + } + + $collection = $results; + + if (!$results instanceof BaseCollection) { + /** @phpstan-ignore-next-line */ + $collection = collect($results->items()); + } + + /** @phpstan-ignore-next-line */ + $collection->each(function ($model) { + $id = strval($model->{$this->primaryKey}); + + data_set($this->setUp, 'detail', (array) $this->setUp['detail']); + + $state = data_get($this->setUp, 'detail.state.' . $id, false); + + data_set($this->setUp, 'detail.state.' . $id, $state); + }); + } + /** * @throws Exception|Throwable */ @@ -361,6 +386,8 @@ public function render(): Application|Factory|View $data = $this->getCachedData(); + $this->resolveDetailRow($data); + if (method_exists($this, 'initActions')) { $this->initActions(); diff --git a/src/ProcessDataSource.php b/src/ProcessDataSource.php index bf69002f..a1738324 100644 --- a/src/ProcessDataSource.php +++ b/src/ProcessDataSource.php @@ -91,8 +91,6 @@ private function processCollection(mixed $datasource): \Illuminate\Pagination\Le $results = $paginated->setCollection($this->transform($paginated->getCollection())); } - self::resolveDetailRow($results); - return $results; } @@ -126,8 +124,6 @@ private function processModel(EloquentBuilder|MorphToMany|QueryBuilder|BaseColle $results = $this->applyPerPage($results); - $this->resolveDetailRow($results); - $this->setTotalCount($results); /** @phpstan-ignore-next-line */ @@ -234,30 +230,6 @@ private function applyPerPage(EloquentBuilder|QueryBuilder|MorphToMany $results) return $results->$paginate($results->count()); } - private function resolveDetailRow(Paginator|LengthAwarePaginator|BaseCollection $results): void - { - if (!isset($this->component->setUp['detail'])) { - return; - } - - $collection = $results; - - if (!$results instanceof BaseCollection) { - $collection = collect($results->items()); - } - - /** @phpstan-ignore-next-line */ - $collection->each(function ($model) { - $id = strval($model->{$this->component->primaryKey}); - - data_set($this->component->setUp, 'detail', (array) $this->component->setUp['detail']); - - $state = data_get($this->component->setUp, 'detail.state.' . $id, false); - - data_set($this->component->setUp, 'detail.state.' . $id, $state); - }); - } - /** * @throws \Exception */ diff --git a/tests/Feature/Filters/FilterMultiSelectTest.php b/tests/Feature/Filters/FilterMultiSelectTest.php index 7a92671d..a99c10b5 100644 --- a/tests/Feature/Filters/FilterMultiSelectTest.php +++ b/tests/Feature/Filters/FilterMultiSelectTest.php @@ -124,7 +124,7 @@ ->assertSee('Name 3') ->assertDontSee('Name 2'); })->group('filters') - ->with('filter_multi_select_themes_collection', 'themes with array table'); + ->with('filter_multi_select_themes_collection'); it('properly filter with category_id - Carnes and Peixe selected', function (string $component) { $multiSelect = Filter::multiSelect('category_name', 'category_id')