"];
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[] =
'
' . $object->text . '
';
// controller
$template =
'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, "") === FALSE) {
$text[] = $line;
}
}
$text = implode("\n", $text);
fclose($file);
$text = str_replace("", 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";
}
}