diff --git a/src/Controllers/GeneratorBuilderController.php b/src/Controllers/GeneratorBuilderController.php index b187a89..bc3420a 100644 --- a/src/Controllers/GeneratorBuilderController.php +++ b/src/Controllers/GeneratorBuilderController.php @@ -10,6 +10,7 @@ use InfyOm\GeneratorBuilder\Requests\BuilderGenerateRequest; use Request; use Response; +use Illuminate\Support\Str; class GeneratorBuilderController extends Controller { @@ -95,6 +96,38 @@ public function generateFromFile() return Response::json(['message' => 'Files created successfully'], 200); } + /** + * Crud generator for generating from DB + */ + public function generateFromDatabase() + { + $data = Request::all(); + + $prefix = $data['prefix']; + $tables = $data['tables']; + + $skipfields = $data['skipfields']; + $input = [ + '--fromTable' => ' ', + ]; + if (!empty($prefix)) { + $input['--prefix'] = $prefix; + } + if (!empty($skipfields)) { + $input['--ignoreFields'] = $skipfields; + } + + foreach ($tables as $key => $table) { + $modelName = str_replace(' ', '', Str::title(str_replace('_', ' ', Str::singular($table)))); + $input['model'] = $modelName; + $input['--tableName'] = $table; + + Artisan::call($data['commandType'], $input); + } + + return Response::json(['message' => 'Files created successfully'], 200); + } + private function validateFields($fields) { $fieldsGroupBy = collect($fields)->groupBy(function ($item) { @@ -203,4 +236,4 @@ private function prepareForeignKeyData($fields) // // return Response::json(json_decode(File::get($filePath))); // } -} \ No newline at end of file +}