diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b37fdfef..4e4ba754 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.0, 8.1] + php: [8.1, 8.2] stability: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} @@ -42,4 +42,4 @@ jobs: command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index a92db286..ecf473b7 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,11 @@ }, "require-dev": { "nunomaduro/larastan": "^2.4", - "orchestra/testbench": "^7.21", + "orchestra/testbench": "^8", "yajra/laravel-datatables-html": "^9.3.4|^10" }, "suggest": { + "yajra/laravel-datatables-export": "Plugin for server-side exporting using livewire and queue worker.", "yajra/laravel-datatables-buttons": "Plugin for server-side exporting of dataTables.", "yajra/laravel-datatables-html": "Plugin for server-side HTML builder of dataTables.", "yajra/laravel-datatables-fractal": "Plugin for server-side response using Fractal.", @@ -65,5 +66,11 @@ "test": "vendor/bin/phpunit" }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/yajra" + } + ] } diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index d35d24f0..bdbfda31 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -106,6 +106,16 @@ public function make($mDataSupport = true): JsonResponse } } + /** + * Get paginated results. + * + * @return \Illuminate\Support\Collection + */ + public function results(): Collection + { + return $this->query->get(); + } + /** * Prepare query by executing count, filter, order and paginate. * @@ -123,7 +133,7 @@ protected function prepareQuery(): static $this->prepared = true; - return $this; + return $this; } /** @@ -146,9 +156,10 @@ public function prepareCountQuery(): QueryBuilder $builder = clone $this->query; if ($this->isComplexQuery($builder)) { - $table = $this->getConnection()->raw('('.$builder->toSql().') count_row_table'); - - return $this->getConnection()->table($table)->setBindings($builder->getBindings()); + return $this->getConnection() + ->query() + ->fromRaw('('.$builder->toSql().') count_row_table') + ->setBindings($builder->getBindings()); } $row_count = $this->wrap('row_count'); @@ -182,16 +193,6 @@ protected function wrap(string $column): string return $this->getConnection()->getQueryGrammar()->wrap($column); } - /** - * Get paginated results. - * - * @return \Illuminate\Support\Collection - */ - public function results(): Collection - { - return $this->query->get(); - } - /** * Keep the select bindings. * @@ -309,6 +310,16 @@ protected function getBaseQueryBuilder($instance = null) return $instance; } + /** + * Get query builder instance. + * + * @return QueryBuilder + */ + public function getQuery(): QueryBuilder + { + return $this->query; + } + /** * Resolve the proper column name be used. * @@ -524,20 +535,6 @@ public function orderByNullsLast(): static return $this; } - /** - * Paginate dataTable using limit without offset - * with additional where clause via callback. - * - * @param callable $callback - * @return $this - */ - public function limit(callable $callback): static - { - $this->limitCallback = $callback; - - return $this; - } - /** * Perform pagination. * @@ -558,6 +555,20 @@ public function paging(): void } } + /** + * Paginate dataTable using limit without offset + * with additional where clause via callback. + * + * @param callable $callback + * @return $this + */ + public function limit(callable $callback): static + { + $this->limitCallback = $callback; + + return $this; + } + /** * Add column in collection. * @@ -778,14 +789,4 @@ public function getFilteredQuery(): QueryBuilder return $this->getQuery(); } - - /** - * Get query builder instance. - * - * @return QueryBuilder - */ - public function getQuery(): QueryBuilder - { - return $this->query; - } }