diff --git a/src/CrudMake.php b/src/CrudMake.php index 652b640..d8da5d7 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -4,9 +4,19 @@ namespace Luthfi\CrudGenerator; use Illuminate\Support\Str; use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; class CrudMake extends Command { + private $files; + + public function __construct(Filesystem $files) + { + parent::__construct(); + + $this->files = $files; + } + /** * The name and signature of the console command. * @@ -30,13 +40,26 @@ class CrudMake extends Command { $model = $this->argument('name'); $pluralModel = str_plural($model); + $lowerCasePluralModel = strtolower($pluralModel); + $this->callSilent('make:model', ['name' => $model]); $this->info($model.' model generated.'); $this->callSilent('make:controller', ['name' => $pluralModel.'Controller']); $this->info($pluralModel.'Controller generated.'); + + $path = resource_path('views/'.$lowerCasePluralModel); + if (! $this->files->isDirectory($path)) { + $this->files->makeDirectory($path, 0777, true, true); + } + + $this->files->put($path.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub')); + $this->files->put($path.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub')); + $this->callSilent('make:test', ['name' => 'Manage'.$pluralModel.'Test']); + $this->info('Manage'.$pluralModel.'Test generated.'); $this->callSilent('make:test', ['name' => 'Models/'.$model.'Test', '--unit' => true]); + $this->info($model.'Test (model) generated.'); $this->info('CRUD files generated successfully!'); } diff --git a/src/stubs/view-forms.stub b/src/stubs/view-forms.stub new file mode 100644 index 0000000..6e03d78 --- /dev/null +++ b/src/stubs/view-forms.stub @@ -0,0 +1,33 @@ +@if (Request::get('action') == 'create') + {!! Form::open(['route' => 'masters.store']) !!} + {!! FormField::text('name') !!} + {!! FormField::textarea('description') !!} + {!! Form::submit(trans('master.create'), ['class' => 'btn btn-success']) !!} + {!! Form::hidden('cat', 'master') !!} + {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'edit' && $editableMaster) + {!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!} + {!! FormField::text('name') !!} + {!! FormField::textarea('description') !!} + {!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'delete' && $editableMaster) +
{{ $editableMaster->name }}
+ {!! $errors->first('master_id', ':message') !!} +| {{ trans('app.table_no') }} | +{{ trans('master.name') }} | +{{ trans('master.description') }} | +{{ trans('app.action') }} | +
|---|---|---|---|
| {{ 1 + $key }} | +{{ $master->name }} | +{{ $master->description }} | ++ {!! link_to_route('masters.index', trans('app.edit'), ['action' => 'edit', 'id' => $master->id], ['id' => 'edit-master-' . $master->id]) !!} | + {!! link_to_route('masters.index', trans('app.delete'), ['action' => 'delete', 'id' => $master->id], ['id' => 'del-master-' . $master->id]) !!} + | +