Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generateFromDatabase method ...Update GeneratorBuilderController.php #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Controllers/GeneratorBuilderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use InfyOm\GeneratorBuilder\Requests\BuilderGenerateRequest;
use Request;
use Response;
use Illuminate\Support\Str;

class GeneratorBuilderController extends Controller
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -203,4 +236,4 @@ private function prepareForeignKeyData($fields)
//
// return Response::json(json_decode(File::get($filePath)));
// }
}
}