|
@@ -268,7 +268,7 @@ class GenController {
|
|
|
|
|
|
if($controller->hasAdd) {
|
|
if($controller->hasAdd) {
|
|
$addLink = "<a class='btn btn-primary btn-sm' href='/{$controller->name}/add_new'>" .
|
|
$addLink = "<a class='btn btn-primary btn-sm' href='/{$controller->name}/add_new'>" .
|
|
- "<i class='fa fa-plus-circle' aria-hidden='true'></i>Add New</a>";
|
|
|
|
|
|
+ "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
|
|
$text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
|
|
$text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -367,7 +367,25 @@ class GenController {
|
|
}
|
|
}
|
|
public function saveAddNewView(GenController $controller, GenControllerMethod $method)
|
|
public function saveAddNewView(GenController $controller, GenControllerMethod $method)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/add_new.template.blade.php'));
|
|
|
|
+ $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
|
|
+ $text = str_replace("_BACK_ROUTE_", "{$controller->name}-index", $text);
|
|
|
|
+ $columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
|
|
+ $fields = [];
|
|
|
|
+ foreach ($columns as $column) {
|
|
|
|
+ if(in_array($column,
|
|
|
|
+ ['id', 'uid', 'created_at',
|
|
|
|
+ 'deactivated_at', 'deactivation_memo',
|
|
|
|
+ 'reactivated_at', 'reactivation_memo']) === true) continue;
|
|
|
|
+ $fields[] =
|
|
|
|
+ "<div class='form-group mb-3'>" .
|
|
|
|
+ "<label class='control-label'>{$this->snakeToTitleCase($column)}</label>" .
|
|
|
|
+ "<input class='form-control' type='text' name='{$this->snakeToCamelCase($column)}'>" .
|
|
|
|
+ "</div>";
|
|
|
|
+ }
|
|
|
|
+ $text = str_replace("<!-- _SCAFFOLD_FIELDS_ -->", implode("\n", $fields), $text);
|
|
|
|
+ $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
|
|
|
|
+ echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
}
|
|
}
|
|
public function saveRoutes() {
|
|
public function saveRoutes() {
|
|
$lines = ["// --- {$this->root}: {$this->name} --- //"];
|
|
$lines = ["// --- {$this->root}: {$this->name} --- //"];
|
|
@@ -410,6 +428,12 @@ class GenController {
|
|
$text = preg_replace("/([a-z])([A-Z])/", "$1 $2", $text);
|
|
$text = preg_replace("/([a-z])([A-Z])/", "$1 $2", $text);
|
|
return ucwords($text);
|
|
return ucwords($text);
|
|
}
|
|
}
|
|
|
|
+ public function snakeToCamelCase($text) {
|
|
|
|
+ $text = ucwords(str_replace("_", " ", $text));
|
|
|
|
+ $text = str_replace(" ", "", $text);
|
|
|
|
+ $text[0] = strtolower($text[0]);
|
|
|
|
+ return $text;
|
|
|
|
+ }
|
|
private function file_force_contents($dir, $contents){
|
|
private function file_force_contents($dir, $contents){
|
|
$dir = str_replace("\\", "/", $dir);
|
|
$dir = str_replace("\\", "/", $dir);
|
|
$dir = str_replace( '//', '/', $dir);
|
|
$dir = str_replace( '//', '/', $dir);
|