Skip to content

Commit

Permalink
[5.x] Fix error when serializing eloquent query builders (#10189)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored May 28, 2024
1 parent 14716a2 commit 55ea07d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Query/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 55ea07d

Please sign in to comment.