Skip to content

Commit

Permalink
Merge pull request #99 from crynobone/queued-export
Browse files Browse the repository at this point in the history
Allow QueuedExport to serialize query builder (to array) using laravie/serializes-queries
  • Loading branch information
patrickbrouwers authored Oct 8, 2020
2 parents d3c17f7 + c902b1c commit 285cdff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"require": {
"php": ">=7.1.0",
"laravel/nova": "*",
"laravie/serialize-queries": "^0.2",
"maatwebsite/excel": "^3.1"
},
"autoload": {
Expand Down
15 changes: 11 additions & 4 deletions src/Actions/QueuedExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Maatwebsite\LaravelNovaExcel\Actions;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
use Laravel\Nova\Nova;
use Laravie\SerializesQuery\Eloquent;
use Maatwebsite\LaravelNovaExcel\Requests\SerializedRequest;

/**
* @deprecated It's currently impossible to queue an export based on dynamic filters due to serialization issues of the query.
*/
class QueuedExport extends ExportToExcel implements ShouldQueue
{
/**
Expand All @@ -25,7 +24,11 @@ public function __sleep()
$this->request = SerializedRequest::serialize($this->request);
}

return ['headings', 'except', 'only', 'onlyIndexFields', 'request', 'resource'];
if ($this->query instanceof QueryBuilder) {
$this->query = Eloquent::serialize($this->query);
}

return ['headings', 'except', 'only', 'onlyIndexFields', 'request', 'resource', 'query'];
}

/**
Expand All @@ -37,6 +40,10 @@ public function __wakeup()
$this->request = $this->request->unserialize();
}

if (is_array($this->query)) {
$this->query = Eloquent::unserialize($this->query);
}

// Reload Nova resources
Nova::resourcesIn(app_path('Nova'));
}
Expand Down

0 comments on commit 285cdff

Please sign in to comment.