diff --git a/app/Console/Commands/MakeClass.php b/app/Console/Commands/MakeClass.php index 8cd169b23782..bbb0b50d7491 100644 --- a/app/Console/Commands/MakeClass.php +++ b/app/Console/Commands/MakeClass.php @@ -65,8 +65,9 @@ class MakeClass extends GeneratorCommand 'LOWER_NAME' => $module->getLowerName(), 'CLASS' => $this->getClass(), 'STUDLY_NAME' => Str::studly($module->getLowerName()), - 'COLUMNS' => $this->getColumns(), + 'DATATABLE_COLUMNS' => $this->getColumns(), 'FORM_FIELDS' => $this->getFormFields(), + 'DATABASE_FIELDS' => $this->getDatabaseFields($module), ]))->render(); } @@ -122,4 +123,18 @@ class MakeClass extends GeneratorCommand return $str; } + + protected function getDatabaseFields($module) + { + $fields = $this->option('fields'); + $fields = explode(',', $fields); + $str = ''; + + foreach ($fields as $field) { + $field = explode(':', $field)[0]; + $str .= "'" . $module->getLowerName() . ".{$field}', "; + } + + return $str; + } } diff --git a/app/Console/Commands/MakeModule.php b/app/Console/Commands/MakeModule.php index d6ba1d52f5e2..c831196c7510 100644 --- a/app/Console/Commands/MakeModule.php +++ b/app/Console/Commands/MakeModule.php @@ -58,7 +58,7 @@ class MakeModule extends Command Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'views', '--fields' => $fields, '--filename' => 'edit.blade']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable', '--fields' => $fields]); - Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository']); + Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository', '--fields' => $fields]); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']); diff --git a/app/Console/Commands/stubs/datatable.stub b/app/Console/Commands/stubs/datatable.stub index 89ee7602ffd1..81496911598f 100644 --- a/app/Console/Commands/stubs/datatable.stub +++ b/app/Console/Commands/stubs/datatable.stub @@ -15,7 +15,7 @@ class $CLASS$Datatable extends EntityDatatable public function columns() { return [ - $COLUMNS$ + $DATATABLE_COLUMNS$ [ 'created_at', function ($model) { diff --git a/app/Console/Commands/stubs/repository.stub b/app/Console/Commands/stubs/repository.stub index cec3e6ce9b79..6bc25b42cf10 100644 --- a/app/Console/Commands/stubs/repository.stub +++ b/app/Console/Commands/stubs/repository.stub @@ -20,6 +20,7 @@ class $STUDLY_NAME$Repository extends BaseRepository $query = DB::table('$LOWER_NAME$') ->where('$LOWER_NAME$.account_id', '=', \Auth::user()->account_id) ->select( + $DATABASE_FIELDS$ '$LOWER_NAME$.public_id', '$LOWER_NAME$.deleted_at', '$LOWER_NAME$.created_at', diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 09bf95f79fca..7548754ca434 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2263,6 +2263,7 @@ $LANG = array( 'toggle_menu' => 'Toggle Menu', 'new_...' => 'New ...', 'list_...' => 'List ...', + 'created_at' => 'Created', );