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(); + } }