diff --git a/src/CrudMake.php b/src/CrudMake.php
index 806a9b5..6a7b3db 100644
--- a/src/CrudMake.php
+++ b/src/CrudMake.php
@@ -109,5 +109,6 @@ class CrudMake extends GeneratorCommand
app('Luthfi\CrudGenerator\Generators\LangFileGenerator', ['command' => $this])->generate();
app('Luthfi\CrudGenerator\Generators\FormViewGenerator', ['command' => $this])->generate();
app('Luthfi\CrudGenerator\Generators\IndexViewGenerator', ['command' => $this])->generate();
+ app('Luthfi\CrudGenerator\Generators\ShowViewGenerator', ['command' => $this])->generate();
}
}
diff --git a/src/Generators/ShowViewGenerator.php b/src/Generators/ShowViewGenerator.php
new file mode 100644
index 0000000..6a9809c
--- /dev/null
+++ b/src/Generators/ShowViewGenerator.php
@@ -0,0 +1,29 @@
+makeDirectory(resource_path('views/'.$this->modelNames['table_name']));
+
+ $this->generateFile($viewPath.'/show.blade.php', $this->getContent('view-show'));
+
+ $this->command->info($this->modelNames['model_name'].' show view file generated.');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function getContent(string $stubName)
+ {
+ return $this->replaceStubString($this->getStubFileContent($stubName));
+ }
+}
diff --git a/src/stubs/view-edit.stub b/src/stubs/view-edit.stub
index dc5de56..52d8537 100644
--- a/src/stubs/view-edit.stub
+++ b/src/stubs/view-edit.stub
@@ -7,14 +7,14 @@
{{ trans('master.edit') }}
- {!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
+ {!! Form::model($singleMstr, ['route' => ['masters.update', $singleMstr->id],'method' => 'patch']) !!}
{!! FormField::text('name', ['required' => true, 'label' => trans('master.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('master.description')]) !!}
{!! Form::close() !!}
diff --git a/src/stubs/view-show.stub b/src/stubs/view-show.stub
new file mode 100644
index 0000000..151784e
--- /dev/null
+++ b/src/stubs/view-show.stub
@@ -0,0 +1,28 @@
+@extends('layouts.app')
+
+@section('title', trans('master.detail'))
+
+@section('content')
+
+
+
+
{{ trans('master.detail') }}
+
+
+
+ | {{ trans('master.name') }} |
+ {{ $singleMstr->name }} |
+
+
+ | {{ trans('master.description') }} |
+ {{ $singleMstr->description }} |
+
+
+
+
+
+
+
+@endsection
diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php
index c73c0a9..acc6ca4 100644
--- a/tests/Generators/ViewsGeneratorTest.php
+++ b/tests/Generators/ViewsGeneratorTest.php
@@ -77,6 +77,45 @@ class ViewsGeneratorTest extends TestCase
}
/** @test */
+ public function it_creates_correct_show_view_content()
+ {
+ $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
+
+ $showFormViewPath = resource_path("views/{$this->table_name}/show.blade.php");
+ $this->assertFileExists($showFormViewPath);
+ $showFormViewContent = "@extends('layouts.app')
+
+@section('title', trans('{$this->lang_name}.detail'))
+
+@section('content')
+
+
+
+
{{ trans('{$this->lang_name}.detail') }}
+
+
+
+ | {{ trans('{$this->lang_name}.name') }} |
+ {{ \${$this->single_model_var_name}->name }} |
+
+
+ | {{ trans('{$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()
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
@@ -126,14 +165,14 @@ class ViewsGeneratorTest extends TestCase
{{ trans('{$this->lang_name}.edit') }}
- {!! Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}->id],'method' => 'patch']) !!}
+ {!! Form::model(\${$this->single_model_var_name}, ['route' => ['{$this->table_name}.update', \${$this->single_model_var_name}->id],'method' => 'patch']) !!}
{!! FormField::text('name', ['required' => true, 'label' => trans('{$this->lang_name}.name')]) !!}
{!! FormField::textarea('description', ['label' => trans('{$this->lang_name}.description')]) !!}
{!! Form::close() !!}