diff --git a/src/stubs/resources/views/simple/forms-formfield.stub b/src/stubs/resources/views/simple/forms-formfield.stub new file mode 100644 index 0000000..2d3f4fb --- /dev/null +++ b/src/stubs/resources/views/simple/forms-formfield.stub @@ -0,0 +1,63 @@ +@if (Request::get('action') == 'create') +@can('create', new fullMstr) + {{ Form::open(['route' => 'masters.store']) }} + {!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!} + {!! FormField::textarea('description', ['label' => __('master.description')]) !!} + {{ Form::submit(__('master.create'), ['class' => 'btn btn-success']) }} + {{ link_to_route('masters.index', __('app.cancel'), [], ['class' => 'btn btn-default']) }} + {{ Form::close() }} +@endcan +@endif +@if (Request::get('action') == 'edit' && $editableMaster) +@can('update', $editableMaster) + {{ Form::model($editableMaster, ['route' => ['masters.update', $editableMaster], 'method' => 'patch']) }} + {!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!} + {!! FormField::textarea('description', ['label' => __('master.description')]) !!} + @if (request('q')) + {{ Form::hidden('q', request('q')) }} + @endif + @if (request('page')) + {{ Form::hidden('page', request('page')) }} + @endif + {{ Form::submit(__('master.update'), ['class' => 'btn btn-success']) }} + {{ link_to_route('masters.index', __('app.cancel'), Request::only('page', 'q'), ['class' => 'btn btn-default']) }} + @can('delete', $editableMaster) + {{ link_to_route( + 'masters.index', + __('app.delete'), + ['action' => 'delete', 'id' => $editableMaster->id] + Request::only('page', 'q'), + ['id' => 'del-master-'.$editableMaster->id, 'class' => 'btn btn-danger pull-right'] + ) }} + @endcan + {{ Form::close() }} +@endcan +@endif +@if (Request::get('action') == 'delete' && $editableMaster) +@can('delete', $editableMaster) +
+

{{ __('master.delete') }}

+
+ +

{{ $editableMaster->name }}

+ +

{{ $editableMaster->description }}

+ {!! $errors->first('master_id', ':message') !!} +
+
+
{{ __('master.delete_confirm') }}
+ +
+@endcan +@endif diff --git a/src/stubs/resources/views/simple/forms.stub b/src/stubs/resources/views/simple/forms.stub index a98cdc3..dc1399b 100644 --- a/src/stubs/resources/views/simple/forms.stub +++ b/src/stubs/resources/views/simple/forms.stub @@ -1,16 +1,25 @@ @if (Request::get('action') == 'create') @can('create', new fullMstr) - {!! Form::open(['route' => 'masters.store']) !!} - {!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!} - {!! FormField::textarea('description', ['label' => __('master.description')]) !!} - {!! Form::submit(__('master.create'), ['class' => 'btn btn-success']) !!} - {{ link_to_route('masters.index', __('app.cancel'), [], ['class' => 'btn btn-default']) }} - {!! Form::close() !!} +
+ {{ csrf_field() }} +
+ + + {!! $errors->first('name', ':message') !!} +
+
+ + + {!! $errors->first('description', ':message') !!} +
+ + {{ __('app.cancel') }} +
@endcan @endif @if (Request::get('action') == 'edit' && $editableMaster) @can('update', $editableMaster) - {!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster], 'method' => 'patch']) !!} + {{ Form::model($editableMaster, ['route' => ['masters.update', $editableMaster], 'method' => 'patch']) }} {!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!} {!! FormField::textarea('description', ['label' => __('master.description')]) !!} @if (request('q')) @@ -19,17 +28,17 @@ @if (request('page')) {{ Form::hidden('page', request('page')) }} @endif - {!! Form::submit(__('master.update'), ['class' => 'btn btn-success']) !!} + {{ Form::submit(__('master.update'), ['class' => 'btn btn-success']) }} {{ link_to_route('masters.index', __('app.cancel'), Request::only('page', 'q'), ['class' => 'btn btn-default']) }} @can('delete', $editableMaster) - {!! link_to_route( + {{ link_to_route( 'masters.index', __('app.delete'), ['action' => 'delete', 'id' => $editableMaster->id] + Request::only('page', 'q'), ['id' => 'del-master-'.$editableMaster->id, 'class' => 'btn btn-danger pull-right'] - ) !!} + ) }} @endcan - {!! Form::close() !!} + {{ Form::close() }} @endcan @endif @if (Request::get('action') == 'delete' && $editableMaster) diff --git a/tests/Generators/Simple/ViewsGeneratorTest.php b/tests/Generators/Simple/ViewsGeneratorTest.php index 01de64e..089be3f 100644 --- a/tests/Generators/Simple/ViewsGeneratorTest.php +++ b/tests/Generators/Simple/ViewsGeneratorTest.php @@ -88,17 +88,26 @@ class ViewsGeneratorTest extends TestCase $this->assertFileExists($formViewPath); $formViewContent = "@if (Request::get('action') == 'create') @can('create', new {$this->full_model_name}) - {!! Form::open(['route' => '{$this->table_name}.store']) !!} - {!! FormField::text('name', ['required' => true, 'label' => __('{$this->lang_name}.name')]) !!} - {!! FormField::textarea('description', ['label' => __('{$this->lang_name}.description')]) !!} - {!! Form::submit(__('{$this->lang_name}.create'), ['class' => 'btn btn-success']) !!} - {{ link_to_route('{$this->table_name}.index', __('app.cancel'), [], ['class' => 'btn btn-default']) }} - {!! Form::close() !!} +
table_name}.store') }}\" accept-charset=\"UTF-8\"> + {{ csrf_field() }} +
has('name') ? ' has-error' : '' }}\"> + + + {!! \$errors->first('name', ':message') !!} +
+
has('description') ? ' has-error' : '' }}\"> + + + {!! \$errors->first('description', ':message') !!} +
+ lang_name}.create') }}\" class=\"btn btn-success\"> + table_name}.index') }}\" class=\"btn btn-default\">{{ __('app.cancel') }} +
@endcan @endif @if (Request::get('action') == 'edit' && \$editable{$this->model_name}) @can('update', \$editable{$this->model_name}) - {!! Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}], 'method' => 'patch']) !!} + {{ Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}], 'method' => 'patch']) }} {!! FormField::text('name', ['required' => true, 'label' => __('{$this->lang_name}.name')]) !!} {!! FormField::textarea('description', ['label' => __('{$this->lang_name}.description')]) !!} @if (request('q')) @@ -107,17 +116,17 @@ class ViewsGeneratorTest extends TestCase @if (request('page')) {{ Form::hidden('page', request('page')) }} @endif - {!! Form::submit(__('{$this->lang_name}.update'), ['class' => 'btn btn-success']) !!} + {{ Form::submit(__('{$this->lang_name}.update'), ['class' => 'btn btn-success']) }} {{ link_to_route('{$this->table_name}.index', __('app.cancel'), Request::only('page', 'q'), ['class' => 'btn btn-default']) }} @can('delete', \$editable{$this->model_name}) - {!! link_to_route( + {{ link_to_route( '{$this->table_name}.index', __('app.delete'), ['action' => 'delete', 'id' => \$editable{$this->model_name}->id] + Request::only('page', 'q'), ['id' => 'del-{$this->lang_name}-'.\$editable{$this->model_name}->id, 'class' => 'btn btn-danger pull-right'] - ) !!} + ) }} @endcan - {!! Form::close() !!} + {{ Form::close() }} @endcan @endif @if (Request::get('action') == 'delete' && \$editable{$this->model_name})