From a745c46c6ccedca5e715d8f074423546ae73c842 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 1 Oct 2020 14:12:13 +0000 Subject: [PATCH 1/2] Allow QueuedExport to serialize query builder (to array) using laravie/serializes-queries. --- composer.json | 1 + src/Actions/QueuedExport.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f576790..3a162cb 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "require": { "php": ">=7.1.0", "laravel/nova": "*", + "laravie/serialize-queries": "^0.2", "maatwebsite/excel": "^3.1" }, "autoload": { diff --git a/src/Actions/QueuedExport.php b/src/Actions/QueuedExport.php index 7187754..f62a835 100644 --- a/src/Actions/QueuedExport.php +++ b/src/Actions/QueuedExport.php @@ -3,12 +3,11 @@ namespace Maatwebsite\LaravelNovaExcel\Actions; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Database\Eloquent\Builder as QueryBuilder; +use Laravie\SerializesQuery\Eloquent; use Laravel\Nova\Nova; 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 { /** @@ -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']; } /** @@ -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')); } From c902b1c361ce100b9ef472ae3b086130b2cb57f5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 3 Oct 2020 22:16:31 +0800 Subject: [PATCH 2/2] Fixes CS. Signed-off-by: Mior Muhammad Zaki --- src/Actions/QueuedExport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Actions/QueuedExport.php b/src/Actions/QueuedExport.php index f62a835..d247a71 100644 --- a/src/Actions/QueuedExport.php +++ b/src/Actions/QueuedExport.php @@ -4,8 +4,8 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Builder as QueryBuilder; -use Laravie\SerializesQuery\Eloquent; use Laravel\Nova\Nova; +use Laravie\SerializesQuery\Eloquent; use Maatwebsite\LaravelNovaExcel\Requests\SerializedRequest; class QueuedExport extends ExportToExcel implements ShouldQueue