From aff87cae9c50b23649138cef4f9d388c22241d19 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 24 May 2024 16:12:19 +0100 Subject: [PATCH] Properly serialize and unserialize the query builder --- src/Query/EloquentQueryBuilder.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Query/EloquentQueryBuilder.php b/src/Query/EloquentQueryBuilder.php index 6d6f32822e..e12b349e0b 100644 --- a/src/Query/EloquentQueryBuilder.php +++ b/src/Query/EloquentQueryBuilder.php @@ -516,8 +516,21 @@ protected function enforceOrderBy() } } - public function __sleep() + public function __serialize(): array { - return array_keys(Arr::except(get_object_vars($this), ['builder'])); + $this->builder->getQuery()->connection = null; + $this->builder->getQuery()->grammar = null; + + return get_object_vars($this); + } + + public function __unserialize($data): void + { + foreach ($data as $key => $value) { + $this->$key = $value; + } + + $this->builder->getQuery()->connection = $this->builder->getModel()->getConnection(); + $this->builder->getQuery()->grammar = $this->builder->getQuery()->connection->getQueryGrammar(); } }