Skip to content

Commit

Permalink
Properly serialize and unserialize the query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed May 24, 2024
1 parent a4e0425 commit aff87ca
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Query/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit aff87ca

Please sign in to comment.