/** * Persist the model in the web service as a duplicate and restore the model's properties. * * @param int|string $newPrimaryKey * @return Model|null */ public function duplicate($newPrimaryKey = null) { if ($this->exists) { $response = $this->client->cloneObject($this->type, $this->original, $this->getDirty(), $newPrimaryKey); $model = $this->newInstance($response); $model->exists = true; $this->restore(); return $model; } }