/** * Remove relationships from the model * * @param $fileContents * @return string */ private function removeRelationships($fileContents) { foreach ($this->model->getRelationshipsToRemove() as $relation) { $name = $relation->getName(); if (strpos($fileContents, $name) !== false) { $fileContents = preg_replace("/public\\s+function\\s+{$name}\\s*\\(.*?\\).*?\\{.*?\\}/s", "", $fileContents); } } return $fileContents; }
/** * Content to be added for the down migration * * @param bool $tableCreated * @param string $tableName * @return string */ private function migrationDownContents($tableCreated, $tableName) { $removedProperties = $this->model->getPropertiesToRemove(); $functionContents = ""; if (!$tableCreated) { $functionContents = "\t\tSchema::dropIfExists('" . $tableName . "');\n"; } else { if (!empty($this->columnsAdded)) { $functionContents = $this->removePropertiesFromTable($tableName); } else { if (!empty($removedProperties)) { $functionContents = $this->addPropertiesToTable($tableName, $removedProperties); } } $removedRelationships = $this->model->getRelationshipsToRemove(); if (!empty($removedRelationships)) { $functionContents = $this->rollbackForRemovedProperties($removedRelationships, $tableName); } } return $functionContents; }