From 55ea07dbc2f55b83931ab07383e45dfdc5b717fa Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 28 May 2024 18:59:12 +0100 Subject: [PATCH] [5.x] Fix error when serializing eloquent query builders (#10189) --- src/Query/EloquentQueryBuilder.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Query/EloquentQueryBuilder.php b/src/Query/EloquentQueryBuilder.php index 5297ac77aa..e12b349e0b 100644 --- a/src/Query/EloquentQueryBuilder.php +++ b/src/Query/EloquentQueryBuilder.php @@ -515,4 +515,22 @@ protected function enforceOrderBy() $this->orderBy($this->builder->getModel()->getQualifiedKeyName(), 'asc'); } } + + public function __serialize(): array + { + $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(); + } }