Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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"
}
]
}
77 changes: 39 additions & 38 deletions src/QueryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ public function make($mDataSupport = true): JsonResponse
}
}

/**
* Get paginated results.
*
* @return \Illuminate\Support\Collection<int, array>
*/
public function results(): Collection
{
return $this->query->get();
}

/**
* Prepare query by executing count, filter, order and paginate.
*
Expand All @@ -123,7 +133,7 @@ protected function prepareQuery(): static

$this->prepared = true;

return $this;
return $this;
}

/**
Expand All @@ -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');
Expand Down Expand Up @@ -182,16 +193,6 @@ protected function wrap(string $column): string
return $this->getConnection()->getQueryGrammar()->wrap($column);
}

/**
* Get paginated results.
*
* @return \Illuminate\Support\Collection<int, array>
*/
public function results(): Collection
{
return $this->query->get();
}

/**
* Keep the select bindings.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -778,14 +789,4 @@ public function getFilteredQuery(): QueryBuilder

return $this->getQuery();
}

/**
* Get query builder instance.
*
* @return QueryBuilder
*/
public function getQuery(): QueryBuilder
{
return $this->query;
}
}