|
@@ -0,0 +1,161 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Console\Commands;
|
|
|
|
+
|
|
|
|
+use Illuminate\Console\Command;
|
|
|
|
+
|
|
|
|
+class GenerateCCommand extends Command
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * The name and signature of the console command.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $signature = 'generatec
|
|
|
|
+ {path: /path/to/controller.json}';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The console command description.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $description = 'Command description';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Create a new command instance.
|
|
|
|
+ *
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ public function __construct()
|
|
|
|
+ {
|
|
|
|
+ parent::__construct();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Execute the console command.
|
|
|
|
+ *
|
|
|
|
+ * @return mixed
|
|
|
|
+ */
|
|
|
|
+ public function handle()
|
|
|
|
+ {
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ global $argv;
|
|
|
|
+ $controllers = json_decode(file_get_contents($argv[2]));
|
|
|
|
+
|
|
|
|
+// Route::get('/my-payments-schedule', 'MyPaymentScheduleController@index');
|
|
|
|
+// Route::get('/my-teams', 'MyTeamsController@index');
|
|
|
|
+// Route::get('/my-clients', 'MyClientsController@index');
|
|
|
|
+// Route::get('/notes', 'NotesController@index');
|
|
|
|
+// Route::get('/erx', 'ERXController@index');
|
|
|
|
+// Route::get('/action-items', 'ActionItemsController@index');
|
|
|
|
+// Route::get('/care-months', 'CareMonthsController@index');
|
|
|
|
+// Route::get('/bills', 'BillsController@index');
|
|
|
|
+// Route::get('/transactions', 'TransactionsController@index');
|
|
|
|
+// Route::get('/med-profile-lines', 'MedProfileLinesController@index');
|
|
|
|
+// Route::get('/mcp-updates', 'McpUpdatesController@index');
|
|
|
|
+// Route::get('/ally-updates', 'AllyUpdatesController@index');
|
|
|
|
+// Route::get('/audit-log', 'AuditLogController@index');
|
|
|
|
+
|
|
|
|
+ $routesText = ["/* __SCAFFOLD_ROUTES__ */"];
|
|
|
|
+ $linksText = ["<!-- __SCAFFOLD_LINKS__ -->"];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ foreach ($controllers as $name => $object) {
|
|
|
|
+
|
|
|
|
+ if(isset($object->todo)) continue;
|
|
|
|
+
|
|
|
|
+ // 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');";
|
|
|
|
+
|
|
|
|
+ // 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
|
|
|
|
+ $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"))) {
|
|
|
|
+ file_put_contents(app_path("Http/Controllers/{$name}Controller.php"), $text);
|
|
|
|
+ echo "Generated " . app_path("Http/Controllers/{$name}Controller.php") . "\n";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // write routes
|
|
|
|
+ $text = [];
|
|
|
|
+ $file = fopen(base_path("routes/web.php"), "r");
|
|
|
|
+ while (!feof($file)) {
|
|
|
|
+ $line = rtrim(fgets($file));
|
|
|
|
+ if(strpos($line, "/* SCAF */") === FALSE) {
|
|
|
|
+ $text[] = $line;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $text = implode("\n", $text);
|
|
|
|
+ fclose($file);
|
|
|
|
+ $text = str_replace("/* __SCAFFOLD_ROUTES__ */", implode("\n", $routesText), $text);
|
|
|
|
+ file_put_contents(base_path("routes/web.php"), $text);
|
|
|
|
+ echo "Updated " . base_path("routes/web.php") . "\n";
|
|
|
|
+
|
|
|
|
+ // write left nav links
|
|
|
|
+ $text = [];
|
|
|
|
+ $file = fopen(resource_path("views/layouts/pro-logged-in.blade.php"), "r");
|
|
|
|
+ while (!feof($file)) {
|
|
|
|
+ $line = rtrim(fgets($file));
|
|
|
|
+ if(strpos($line, "<!-- SCAF -->") === FALSE) {
|
|
|
|
+ $text[] = $line;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $text = implode("\n", $text);
|
|
|
|
+ fclose($file);
|
|
|
|
+ $text = str_replace("<!-- __SCAFFOLD_LINKS__ -->", implode("\n", $linksText), $text);
|
|
|
|
+ file_put_contents(resource_path("views/layouts/pro-logged-in.blade.php"), $text);
|
|
|
|
+ echo "Updated " . resource_path("views/layouts/pro-logged-in.blade.php") . "\n";
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|