diff --git a/app/Console/Commands/MakeClass.php b/app/Console/Commands/MakeClass.php index 9779c79e5f..8cd169b237 100644 --- a/app/Console/Commands/MakeClass.php +++ b/app/Console/Commands/MakeClass.php @@ -50,6 +50,7 @@ class MakeClass extends GeneratorCommand { return array( array('fields', null, InputOption::VALUE_OPTIONAL, 'The model attributes.', null), + array('filename', null, InputOption::VALUE_OPTIONAL, 'The class filename.', null), ); } @@ -65,6 +66,7 @@ class MakeClass extends GeneratorCommand 'CLASS' => $this->getClass(), 'STUDLY_NAME' => Str::studly($module->getLowerName()), 'COLUMNS' => $this->getColumns(), + 'FORM_FIELDS' => $this->getFormFields(), ]))->render(); } @@ -81,6 +83,9 @@ class MakeClass extends GeneratorCommand */ protected function getFileName() { + if ($this->option('filename')) { + return $this->option('filename'); + } return studly_case($this->argument('prefix')) . studly_case($this->argument('name')) . Str::studly($this->argument('class')); } @@ -103,4 +108,18 @@ class MakeClass extends GeneratorCommand return $str; } + protected function getFormFields() + { + $fields = $this->option('fields'); + $fields = explode(',', $fields); + $str = ''; + + foreach ($fields as $field) { + $field = explode(':', $field)[0]; + $str .= '{!! Former::text(\''. $field . '\') !!} + '; + } + + return $str; + } } diff --git a/app/Console/Commands/MakeModule.php b/app/Console/Commands/MakeModule.php index f2e681e8ab..d6ba1d52f5 100644 --- a/app/Console/Commands/MakeModule.php +++ b/app/Console/Commands/MakeModule.php @@ -56,12 +56,12 @@ class MakeModule extends Command Artisan::call('module:migrate', ['module' => $name]); Artisan::call('module:make-model', ['model' => $name, 'module' => $name, '--fillable' => $fillable]); + 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' => 'policy']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']); - Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'create']); Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'update']); diff --git a/app/Console/Commands/stubs/repository.stub b/app/Console/Commands/stubs/repository.stub index b003e73fae..cec3e6ce9b 100644 --- a/app/Console/Commands/stubs/repository.stub +++ b/app/Console/Commands/stubs/repository.stub @@ -57,7 +57,7 @@ class $STUDLY_NAME$Repository extends BaseRepository } */ - //$entity->fill($data); + $entity->fill($data); $entity->save(); /* diff --git a/app/Console/Commands/stubs/updaterequest.stub b/app/Console/Commands/stubs/updaterequest.stub index 7577668027..99bf461f00 100644 --- a/app/Console/Commands/stubs/updaterequest.stub +++ b/app/Console/Commands/stubs/updaterequest.stub @@ -11,7 +11,7 @@ class Update$CLASS$Request extends $CLASS$Request */ public function authorize() { - return $this->user()->can('edit', '$LOWER_NAME$'); + return $this->user()->can('edit', $this->entity()); } /** diff --git a/app/Console/Commands/stubs/view.stub b/app/Console/Commands/stubs/view.stub new file mode 100755 index 0000000000..d34ad44c7c --- /dev/null +++ b/app/Console/Commands/stubs/view.stub @@ -0,0 +1,47 @@ +@extends('header') + +@section('content') + + {!! Former::open($url) + ->addClass('col-md-10 col-md-offset-1 warn-on-exit') + ->method($method) + ->rules([]) !!} + + @if ($$LOWER_NAME$) + {!! Former::populate($$LOWER_NAME$) !!} +
+ {!! Former::text('public_id') !!} +
+ @endif + +
+
+ +
+
+ + $FORM_FIELDS$ + +
+
+ +
+
+ +
+ + {!! Button::normal(trans('texts.cancel')) + ->large() + ->asLinkTo(URL::to('/$LOWER_NAME$')) + ->appendIcon(Icon::create('remove-circle')) !!} + + {!! Button::success(trans('texts.save')) + ->submit() + ->large() + ->appendIcon(Icon::create('floppy-disk')) !!} + +
+ + {!! Former::close() !!} + +@stop diff --git a/app/Console/Commands/stubs/views.stub b/app/Console/Commands/stubs/views.stub new file mode 100755 index 0000000000..d34ad44c7c --- /dev/null +++ b/app/Console/Commands/stubs/views.stub @@ -0,0 +1,47 @@ +@extends('header') + +@section('content') + + {!! Former::open($url) + ->addClass('col-md-10 col-md-offset-1 warn-on-exit') + ->method($method) + ->rules([]) !!} + + @if ($$LOWER_NAME$) + {!! Former::populate($$LOWER_NAME$) !!} +
+ {!! Former::text('public_id') !!} +
+ @endif + +
+
+ +
+
+ + $FORM_FIELDS$ + +
+
+ +
+
+ +
+ + {!! Button::normal(trans('texts.cancel')) + ->large() + ->asLinkTo(URL::to('/$LOWER_NAME$')) + ->appendIcon(Icon::create('remove-circle')) !!} + + {!! Button::success(trans('texts.save')) + ->submit() + ->large() + ->appendIcon(Icon::create('floppy-disk')) !!} + +
+ + {!! Former::close() !!} + +@stop diff --git a/app/Console/Commands/stubs/views/edit.stub b/app/Console/Commands/stubs/views/edit.stub index 8b1e1123c2..024e2bf9e5 100755 --- a/app/Console/Commands/stubs/views/edit.stub +++ b/app/Console/Commands/stubs/views/edit.stub @@ -20,7 +20,7 @@
- +
diff --git a/config/modules.php b/config/modules.php index ffec59c66a..8de9da8c5a 100644 --- a/config/modules.php +++ b/config/modules.php @@ -29,7 +29,6 @@ return [ 'start' => 'start.php', 'routes' => 'Http/routes.php', 'json' => 'module.json', - 'views/edit' => 'Resources/views/edit.blade.php', 'views/master' => 'Resources/views/layouts/master.blade.php', 'scaffold/config' => 'Config/config.php', 'composer' => 'composer.json', @@ -38,7 +37,6 @@ return [ 'start' => ['LOWER_NAME'], 'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], 'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'], - 'views/edit' => ['LOWER_NAME'], 'views/master' => ['STUDLY_NAME'], 'scaffold/config' => ['STUDLY_NAME'], 'composer' => [