/** * Migration to drop a table * * @param $timestamp */ public function dropTable(&$timestamp) { $migrationName = "edit_" . $this->model->getTableName() . "_table"; $migrationFile = $this->getMigrationFileName($migrationName, $timestamp); $functionContents = "\t\tSchema::dropIfExists('" . $this->model->getTableName() . "');\n"; $this->currentFileContents = $this->fileCreator->createFunction("up", $functionContents); $functionContents = $this->migrationUp(); $this->currentFileContents .= $this->fileCreator->createFunction("down", $functionContents); $classNameArr = explode("_", $migrationName); $className = ""; foreach ($classNameArr as $class) { $className .= ucfirst($class); } $this->fileCreator->createMigrationClass($migrationFile, $this->currentFileContents, $className); }
/** * Generate a file based off of a template * * @param $fileName * @param $template * @param string $content */ public function makeFileFromTemplate($fileName, $template, $content = "") { try { $fileContents = \File::get($template); } catch (FileNotFoundException $e) { $shortTemplate = substr($template, strpos($template, $this->configSettings["pathTo"]["templates"]) + strlen($this->configSettings["pathTo"]["templates"]), strlen($template) - strlen($this->configSettings["pathTo"]["templates"])); $this->fileCreator->copyFile("vendor/jrenton/laravel-scaffold/src/Jrenton/LaravelScaffold/templates/" . $shortTemplate, $template); $fileContents = \File::get($template); } $fileContents = $this->replaceNames($fileContents); $fileContents = $this->replaceModels($fileContents); $fileContents = $this->replaceProperties($fileContents); if ($content) { $fileContents = str_replace("[content]", $content, $fileContents); } $namespace = $this->namespace ? "namespace " . $this->namespace . ";" : ""; $fileContents = str_replace("[namespace]", $namespace, $fileContents); if (!$this->configSettings['useRepository']) { $fileContents = str_replace($this->nameOf("repositoryInterface"), $this->nameOf("modelName"), $fileContents); } $this->fileCreator->createFile($fileName, $fileContents); }