|
@@ -68,61 +68,66 @@ class GenerateCCommand extends Command
|
|
|
|
|
|
// routes
|
|
|
$routesText[] = "/* SCAF */// $object->slug CRUD";
|
|
|
- $routesText[] = "/* SCAF */Route::get ('/$object->slug', '{$name}Controller@index');";
|
|
|
- $routesText[] = "/* SCAF */Route::get ('/$object->slug/:id', '{$name}Controller@show');";
|
|
|
- $routesText[] = "/* SCAF */Route::get ('/$object->slug/create', '{$name}Controller@create');";
|
|
|
- $routesText[] = "/* SCAF */Route::get ('/$object->slug/update/:id', '{$name}Controller@update');";
|
|
|
+ $routesText[] = "/* SCAF */Route::get ('/$object->slug', '{$name}Controller@index')->name('{$object->slug}-index');";
|
|
|
+ $routesText[] = "/* SCAF */Route::get ('/$object->slug/{id}', '{$name}Controller@show')->name('{$object->slug}-view');";
|
|
|
+ $routesText[] = "/* SCAF */Route::get ('/$object->slug/create', '{$name}Controller@create')->name('{$object->slug}-create');";
|
|
|
+ $routesText[] = "/* SCAF */Route::get ('/$object->slug/update/{id}', '{$name}Controller@update')->name('{$object->slug}-update');";
|
|
|
|
|
|
// left nav links
|
|
|
$linksText[] =
|
|
|
'<!-- SCAF --><li class="nav-item"><a href="/' . $object->slug . '" class="nav-link"><i class="nav-icon ' . $object->icon . '"></i><p>' . $object->text . '</p></a></li>';
|
|
|
|
|
|
// controller
|
|
|
- $template =
|
|
|
-'<?php
|
|
|
-
|
|
|
-namespace App\Http\Controllers;
|
|
|
-
|
|
|
-use Illuminate\Http\Request;
|
|
|
-use App\Models\_MODEL_;
|
|
|
-
|
|
|
-class _NAME_Controller extends Controller
|
|
|
-{
|
|
|
-
|
|
|
- public function index(Request $request)
|
|
|
- {
|
|
|
- $rows = _MODEL_::all();
|
|
|
- return view(\'_SLUG_.index\', compact(\'rows\'));
|
|
|
- }
|
|
|
-
|
|
|
- public function show(Request $request, $uid)
|
|
|
- {
|
|
|
- $row = _MODEL_::where(\'uid\', $uid)->first();
|
|
|
- return view(\'_SLUG_.show\', compact(\'row\'));
|
|
|
- }
|
|
|
-
|
|
|
- public function create(Request $request)
|
|
|
- {
|
|
|
- return view(\'_SLUG_.create\');
|
|
|
- }
|
|
|
-
|
|
|
- public function update(Request $request, $uid)
|
|
|
- {
|
|
|
- $row = _MODEL_::where(\'uid\', $uid)->first();
|
|
|
- return view(\'_SLUG_.update\', compact(\'row\'));
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-';
|
|
|
-
|
|
|
- // write controller
|
|
|
+ $template = file_get_contents(base_path('generatecv/controller.template.php'));
|
|
|
$text = str_replace("_NAME_", $name, $template);
|
|
|
$text = str_replace("_MODEL_", $object->model, $text);
|
|
|
$text = str_replace("_SLUG_", $object->slug, $text);
|
|
|
- if(!file_exists(app_path("Http/Controllers/{$name}Controller.php"))) {
|
|
|
+// if(!file_exists(app_path("Http/Controllers/{$name}Controller.php"))) {
|
|
|
file_put_contents(app_path("Http/Controllers/{$name}Controller.php"), $text);
|
|
|
echo "Generated " . app_path("Http/Controllers/{$name}Controller.php") . "\n";
|
|
|
+// }
|
|
|
+
|
|
|
+ // views - index
|
|
|
+ if(isset($object->list)) {
|
|
|
+ $template = file_get_contents(base_path('generatecv/listing.template.blade.php'));
|
|
|
+ $text = str_replace("_NAME_", $object->text, $template);
|
|
|
+ $text = str_replace("_SLUG_", $object->slug, $text);
|
|
|
+ $ths = [];
|
|
|
+ foreach ($object->list as $field => $display) {
|
|
|
+ $ths[] = "<th>{$display}</th>";
|
|
|
+ }
|
|
|
+ $ths = implode("\n", $ths);
|
|
|
+ $text = str_replace("<!-- __SCAFFOLD_THS__ -->", $ths, $text);
|
|
|
+ $tds = [];
|
|
|
+ foreach ($object->list as $field => $display) {
|
|
|
+ if($field === 'id') {
|
|
|
+ $tds[] = '<td><a href="/' . $object->slug . '/<?= $row->uid ?>"><?= $row->' . $field . ' ?></a></td>';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $tds[] = '<td><?= $row->' . $field . ' ?></td>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $tds = implode("\n", $tds);
|
|
|
+ $text = str_replace("<!-- __SCAFFOLD_TDS__ -->", $tds, $text);
|
|
|
+// if(!file_exists(resource_path("views/{$object->slug}/index.blade.php"))) {
|
|
|
+ $this->file_force_contents(resource_path("views/{$object->slug}/index.blade.php"), $text);
|
|
|
+ echo "Generated " . resource_path("views/{$object->slug}/index.blade.php") . "\n";
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($object->show)) {
|
|
|
+ $template = file_get_contents(base_path('generatecv/show.template.blade.php'));
|
|
|
+ $dts = [];
|
|
|
+ foreach ($object->show as $field => $display) {
|
|
|
+ $dts[] = "<dt class='col-md-2'>{$display}</dt>" .
|
|
|
+ '<dd class="col-md-10"><?= $row->' . $field . ' ?></dd>';
|
|
|
+ }
|
|
|
+ $dts = implode("\n", $dts);
|
|
|
+ $text = str_replace("<!-- __SCAFFOLD_DTS__ -->", $dts, $template);
|
|
|
+// if(!file_exists(resource_path("views/{$object->slug}/show.blade.php"))) {
|
|
|
+ $this->file_force_contents(resource_path("views/{$object->slug}/show.blade.php"), $text);
|
|
|
+ echo "Generated " . resource_path("views/{$object->slug}/show.blade.php") . "\n";
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -158,4 +163,13 @@ class _NAME_Controller extends Controller
|
|
|
echo "Updated " . resource_path("views/layouts/pro-logged-in.blade.php") . "\n";
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private function file_force_contents($dir, $contents){
|
|
|
+ $parts = explode('/', $dir);
|
|
|
+ $file = array_pop($parts);
|
|
|
+ $dir = '';
|
|
|
+ foreach($parts as $part)
|
|
|
+ if(!is_dir($dir .= "/$part")) mkdir($dir);
|
|
|
+ file_put_contents("$dir/$file", $contents);
|
|
|
+ }
|
|
|
}
|