Skip to content

Commit

Permalink
Fixed queryBuilder method bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
allanvb committed May 6, 2021
1 parent 499a741 commit af37762
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes in Laravel Nova Exports will be documented in this file

## 1.0.2
- Fixed queryBuilder method bugs

## 1.0.1
- Added ability to manipulate with the query builder
- Added ability to set own file name
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function actions(Request $request): array
- `withUserSelection()` - Enables multi-select field that allow user to select the columns when exporting.
- `usesDateRange(string $columnName)` - Enables field that allow user to select the range of dates when exporting. *Default: `created_at`*
- `usesGenerator()` - Enables cursor usage when getting data from database.
- `queryBuilder(callable $query)` - Manipulate query builder before data exportation.
- `queryBuilder(callable $query)` - Use own query on data exportation.

*`withUserSelection` method isn't fully supported by `queryBuilder` method. I recommend to not use them together.*
*`withUserSelection` method cannot be used together with `queryBuilder` method.*

You are also able to use all of [Nova Action](https://nova.laravel.com/docs/3.0/actions/defining-actions.html) methods, and all of [Detached Actions](https://github.com/gobrightspot/nova-detached-actions#display-on-different-screens) methods on `ExportResourceAction`.

Expand Down
7 changes: 5 additions & 2 deletions src/ExportResourceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ protected function resourceGenerator(Builder $builder): ?Generator
protected function getQueryData(array $columns, ActionFields $fields)
{
if (!$this->usesOwnQuery) {
$columns = array_map(fn($column) => $this->table.'.'.$column, $columns);

$this->queryBuilder = $this->queryBuilder->select($columns);
}

Expand All @@ -327,7 +329,7 @@ protected function getQueryData(array $columns, ActionFields $fields)
if ($from && $to) {
$this->queryBuilder = $this->queryBuilder
->whereBetween(
$this->rangeColumn,
$this->table . '.' . $this->rangeColumn,
[
Carbon::parse($from)->startOfDay(),
Carbon::parse($to)->endOfDay()
Expand All @@ -336,7 +338,7 @@ protected function getQueryData(array $columns, ActionFields $fields)
} elseif ($from && is_null($to)) {
$this->queryBuilder = $this->queryBuilder
->whereDate(
$this->rangeColumn,
$this->table . '.' . $this->rangeColumn,
Carbon::parse($from)->startOfDay()
);
}
Expand Down Expand Up @@ -366,3 +368,4 @@ protected function getQueryData(array $columns, ActionFields $fields)
return $data;
}
}

0 comments on commit af37762

Please sign in to comment.