diff --git a/src/Generators/FormViewGenerator.php b/src/Generators/FormViewGenerator.php
index 53919af..70fc928 100644
--- a/src/Generators/FormViewGenerator.php
+++ b/src/Generators/FormViewGenerator.php
@@ -29,6 +29,10 @@ class FormViewGenerator extends BaseGenerator
*/
public function getContent(string $stubName)
{
+ if ($this->command->option('formfield')) {
+ $stubName .= '-formfield';
+ }
+
return $this->replaceStubString($this->getStubFileContent($stubName));
}
}
diff --git a/src/Generators/IndexViewGenerator.php b/src/Generators/IndexViewGenerator.php
index f27623f..58b4908 100644
--- a/src/Generators/IndexViewGenerator.php
+++ b/src/Generators/IndexViewGenerator.php
@@ -24,6 +24,10 @@ class IndexViewGenerator extends BaseGenerator
*/
public function getContent(string $stubName)
{
+ if ($this->command->option('formfield')) {
+ $stubName .= '-formfield';
+ }
+
return $this->replaceStubString($this->getStubFileContent($stubName));
}
}
diff --git a/src/Generators/ShowViewGenerator.php b/src/Generators/ShowViewGenerator.php
index e2065e5..11f10b7 100644
--- a/src/Generators/ShowViewGenerator.php
+++ b/src/Generators/ShowViewGenerator.php
@@ -24,6 +24,10 @@ class ShowViewGenerator extends BaseGenerator
*/
public function getContent(string $stubName)
{
+ if ($this->command->option('formfield')) {
+ $stubName .= '-formfield';
+ }
+
return $this->replaceStubString($this->getStubFileContent($stubName));
}
}
diff --git a/src/stubs/resources/views/full/create-formfield.stub b/src/stubs/resources/views/full/create-formfield.stub
index b4f2704..9cd22ca 100644
--- a/src/stubs/resources/views/full/create-formfield.stub
+++ b/src/stubs/resources/views/full/create-formfield.stub
@@ -7,16 +7,16 @@
{{ __('master.create') }}
- {!! Form::open(['route' => 'masters.store']) !!}
+ {{ Form::open(['route' => 'masters.store']) }}
{!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!}
{!! FormField::textarea('description', ['label' => __('master.description')]) !!}
- {!! Form::close() !!}
+ {{ Form::close() }}
diff --git a/src/stubs/resources/views/full/edit-formfield.stub b/src/stubs/resources/views/full/edit-formfield.stub
index d23de5b..71d02ad 100644
--- a/src/stubs/resources/views/full/edit-formfield.stub
+++ b/src/stubs/resources/views/full/edit-formfield.stub
@@ -36,19 +36,19 @@
@else
{{ __('master.edit') }}
- {!! Form::model($singleMstr, ['route' => ['masters.update', $singleMstr],'method' => 'patch']) !!}
+ {{ Form::model($singleMstr, ['route' => ['masters.update', $singleMstr],'method' => 'patch']) }}
{!! FormField::text('name', ['required' => true, 'label' => __('master.name')]) !!}
{!! FormField::textarea('description', ['label' => __('master.description')]) !!}
- {!! Form::close() !!}
+ {{ Form::close() }}
diff --git a/src/stubs/resources/views/full/index-formfield.stub b/src/stubs/resources/views/full/index-formfield.stub
index a10b0a0..66c91fb 100644
--- a/src/stubs/resources/views/full/index-formfield.stub
+++ b/src/stubs/resources/views/full/index-formfield.stub
@@ -39,12 +39,12 @@
{{ $singleMstr->description }} |
@can('view', $singleMstr)
- {!! link_to_route(
+ {{ link_to_route(
'masters.show',
__('app.show'),
[$singleMstr],
['class' => 'btn btn-default btn-xs', 'id' => 'show-master-' . $singleMstr->id]
- ) !!}
+ ) }}
@endcan
|
diff --git a/tests/CommandOptions/FormfieldOptionsTest.php b/tests/CommandOptions/FormfieldOptionsTest.php
deleted file mode 100644
index 87a4c49..0000000
--- a/tests/CommandOptions/FormfieldOptionsTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-artisan('make:crud', [
- 'name' => $this->model_name,
- '--formfield' => true,
- ]);
-
- $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
-
- $this->assertFileExists(app_path($this->model_name.'.php'));
- $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
-
- $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
- $this->assertFileExists($migrationFilePath);
-
- $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
- $this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
- $this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
- $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
-
- $localeConfig = config('app.locale');
- $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
-
- $this->assertFileExists(base_path("routes/web.php"));
- $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
- $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
- $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
- $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
- }
-
- /** @test */
- public function it_can_generate_views_with_formfield_for_simple_crud()
- {
- $this->artisan('make:crud-simple', [
- 'name' => $this->model_name,
- '--formfield' => true,
- ]);
-
- $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
-
- $this->assertFileExists(app_path($this->model_name.'.php'));
- $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
-
- $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
- $this->assertFileExists($migrationFilePath);
-
- $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
- $this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php"));
-
- $localeConfig = config('app.locale');
- $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
-
- $this->assertFileExists(base_path("routes/web.php"));
- $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
- $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
- $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
- $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
- }
-}
diff --git a/tests/CommandOptions/FullCrudFormfieldOptionsTest.php b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php
new file mode 100644
index 0000000..a66c641
--- /dev/null
+++ b/tests/CommandOptions/FullCrudFormfieldOptionsTest.php
@@ -0,0 +1,245 @@
+artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
+
+ $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
+
+ $this->assertFileExists(app_path($this->model_name.'.php'));
+ $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
+
+ $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
+ $this->assertFileExists($migrationFilePath);
+
+ $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
+ $this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php"));
+ $this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php"));
+ $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
+
+ $localeConfig = config('app.locale');
+ $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
+
+ $this->assertFileExists(base_path("routes/web.php"));
+ $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
+ $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
+ $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
+ $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
+ }
+
+ /** @test */
+ public function it_creates_correct_index_view_content_with_formfield()
+ {
+ $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
+
+ $indexViewPath = resource_path("views/{$this->table_name}/index.blade.php");
+ $this->assertFileExists($indexViewPath);
+ $indexViewContent = "@extends('layouts.app')
+
+@section('title', __('{$this->lang_name}.list'))
+
+@section('content')
+
+
+
+
+
+ {{ Form::open(['method' => 'get','class' => 'form-inline']) }}
+ {!! FormField::text('q', ['label' => __('{$this->lang_name}.search'), 'placeholder' => __('{$this->lang_name}.search_text'), 'class' => 'input-sm']) !!}
+ {{ Form::submit(__('{$this->lang_name}.search'), ['class' => 'btn btn-sm']) }}
+ {{ link_to_route('{$this->table_name}.index', __('app.reset')) }}
+ {{ Form::close() }}
+
+
+
+
+ | {{ __('app.table_no') }} |
+ {{ __('{$this->lang_name}.name') }} |
+ {{ __('{$this->lang_name}.description') }} |
+ {{ __('app.action') }} |
+
+
+
+ @foreach(\${$this->collection_model_var_name} as \$key => \${$this->single_model_var_name})
+
+ | {{ \${$this->collection_model_var_name}->firstItem() + \$key }} |
+ {{ \${$this->single_model_var_name}->name_link }} |
+ {{ \${$this->single_model_var_name}->description }} |
+
+ @can('view', \${$this->single_model_var_name})
+ {{ link_to_route(
+ '{$this->table_name}.show',
+ __('app.show'),
+ [\${$this->single_model_var_name}],
+ ['class' => 'btn btn-default btn-xs', 'id' => 'show-{$this->lang_name}-' . \${$this->single_model_var_name}->id]
+ ) }}
+ @endcan
+ |
+
+ @endforeach
+
+
+
{{ \${$this->collection_model_var_name}->appends(Request::except('page'))->render() }}
+
+
+
+@endsection
+";
+ $this->assertEquals($indexViewContent, file_get_contents($indexViewPath));
+ }
+
+ /** @test */
+ public function it_creates_correct_show_view_content_with_formfield()
+ {
+ $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
+
+ $showFormViewPath = resource_path("views/{$this->table_name}/show.blade.php");
+ $this->assertFileExists($showFormViewPath);
+
+ $showFormViewContent = "@extends('layouts.app')
+
+@section('title', __('{$this->lang_name}.detail'))
+
+@section('content')
+
+
+
+
{{ __('{$this->lang_name}.detail') }}
+
+
+ | {{ __('{$this->lang_name}.name') }} | {{ \${$this->single_model_var_name}->name }} |
+ | {{ __('{$this->lang_name}.description') }} | {{ \${$this->single_model_var_name}->description }} |
+
+
+
+
+
+
+@endsection
+";
+ $this->assertEquals($showFormViewContent, file_get_contents($showFormViewPath));
+ }
+
+ /** @test */
+ public function it_creates_correct_create_view_content_with_formfield()
+ {
+ $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
+
+ $createFormViewPath = resource_path("views/{$this->table_name}/create.blade.php");
+ $this->assertFileExists($createFormViewPath);
+ $createFormViewContent = "@extends('layouts.app')
+
+@section('title', __('{$this->lang_name}.create'))
+
+@section('content')
+
+
+
+
{{ __('{$this->lang_name}.create') }}
+ {{ 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::close() }}
+
+
+
+@endsection
+";
+ $this->assertEquals($createFormViewContent, file_get_contents($createFormViewPath));
+ }
+
+ /** @test */
+ public function it_creates_correct_edit_view_content_with_formfield()
+ {
+ $this->artisan('make:crud', ['name' => $this->model_name, '--formfield' => true]);
+
+ $editFormViewPath = resource_path("views/{$this->table_name}/edit.blade.php");
+ $this->assertFileExists($editFormViewPath);
+ $editFormViewContent = "@extends('layouts.app')
+
+@section('title', __('{$this->lang_name}.edit'))
+
+@section('content')
+
+
+ @if (request('action') == 'delete' && \${$this->single_model_var_name})
+ @can('delete', \${$this->single_model_var_name})
+
+
{{ __('{$this->lang_name}.delete') }}
+
+
+
{{ \${$this->single_model_var_name}->name }}
+
+
{{ \${$this->single_model_var_name}->description }}
+ {!! \$errors->first('{$this->lang_name}_id', '
:message') !!}
+
+
+
{{ __('{$this->lang_name}.delete_confirm') }}
+
+
+ @endcan
+ @else
+
+
{{ __('{$this->lang_name}.edit') }}
+ {{ Form::model(\${$this->single_model_var_name}, ['route' => ['{$this->table_name}.update', \${$this->single_model_var_name}],'method' => 'patch']) }}
+
+ {!! FormField::text('name', ['required' => true, 'label' => __('{$this->lang_name}.name')]) !!}
+ {!! FormField::textarea('description', ['label' => __('{$this->lang_name}.description')]) !!}
+
+
+ {{ Form::close() }}
+
+
+
+@endif
+@endsection
+";
+ $this->assertEquals($editFormViewContent, file_get_contents($editFormViewPath));
+ }
+
+}
diff --git a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php
new file mode 100644
index 0000000..8891e9d
--- /dev/null
+++ b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php
@@ -0,0 +1,38 @@
+artisan('make:crud-simple', [
+ 'name' => $this->model_name,
+ '--formfield' => true,
+ ]);
+
+ $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output());
+
+ $this->assertFileExists(app_path($this->model_name.'.php'));
+ $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php"));
+
+ $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php');
+ $this->assertFileExists($migrationFilePath);
+
+ $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
+ $this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php"));
+
+ $localeConfig = config('app.locale');
+ $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
+
+ $this->assertFileExists(base_path("routes/web.php"));
+ $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
+ $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
+ $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php"));
+ $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php"));
+ }
+}