diff --git a/src/CrudMake.php b/src/CrudMake.php index e73c700..d9c3062 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -122,12 +122,14 @@ class CrudMake extends Command public function getIndexViewContent() { - return $this->files->get(__DIR__.'/stubs/view-index.stub'); + $stub = $this->files->get(__DIR__.'/stubs/view-index.stub'); + return $this->replaceViewDummyStrings($stub)->replaceClass($stub); } public function getFormsViewContent() { - return $this->files->get(__DIR__.'/stubs/view-forms.stub'); + $stub = $this->files->get(__DIR__.'/stubs/view-forms.stub'); + return $this->replaceViewDummyStrings($stub)->replaceClass($stub); } public function getFeatureTestContent() @@ -195,6 +197,17 @@ class CrudMake extends Command return $this; } + protected function replaceViewDummyStrings(&$stub) + { + $stub = str_replace( + ['Master', 'master', 'masters'], + [$this->modelName, strtolower($this->modelName), $this->lowerCasePluralModel], + $stub + ); + + return $this; + } + protected function replaceClass($stub) { $class = str_plural($this->modelName); diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index d3565b6..252df0d 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -15,11 +15,11 @@ class ViewsGeneratorTest extends TestCase $this->assertFileExists($indexViewPath); $indexViewContent = "@extends('layouts.app') -@section('title', trans('master.list')) +@section('title', trans('item.list')) @section('content') -{{ link_to_route('masters.index', trans('master.create'), ['action' => 'create'], ['class' => 'btn btn-success pull-right']) }} -

{{ trans('master.list') }}

+{{ link_to_route('items.index', trans('item.create'), ['action' => 'create'], ['class' => 'btn btn-success pull-right']) }} +

{{ trans('item.list') }}

@@ -27,20 +27,20 @@ class ViewsGeneratorTest extends TestCase {{ trans('app.table_no') }} - {{ trans('master.name') }} - {{ trans('master.description') }} + {{ trans('item.name') }} + {{ trans('item.description') }} {{ trans('app.action') }} - @foreach(\$masters as \$key => \$master) + @foreach(\$items as \$key => \$item) {{ 1 + \$key }} - {{ \$master->name }} - {{ \$master->description }} + {{ \$item->name }} + {{ \$item->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]) !!} + {!! link_to_route('items.index', trans('app.edit'), ['action' => 'edit', 'id' => \$item->id], ['id' => 'edit-item-' . \$item->id]) !!} | + {!! link_to_route('items.index', trans('app.delete'), ['action' => 'delete', 'id' => \$item->id], ['id' => 'del-item-' . \$item->id]) !!} @endforeach @@ -49,7 +49,7 @@ class ViewsGeneratorTest extends TestCase
- @includeWhen(Request::has('action'), 'masters.forms') + @includeWhen(Request::has('action'), 'items.forms')
@endsection @@ -65,35 +65,35 @@ class ViewsGeneratorTest extends TestCase $formViewPath = resource_path("views/{$this->tableName}/forms.blade.php"); $this->assertFileExists($formViewPath); $formViewContent = "@if (Request::get('action') == 'create') - {!! Form::open(['route' => 'masters.store']) !!} + {!! Form::open(['route' => 'items.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::submit(trans('item.create'), ['class' => 'btn btn-success']) !!} + {!! Form::hidden('cat', 'item') !!} + {{ link_to_route('items.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']) !!} +@if (Request::get('action') == 'edit' && \$editableItem) + {!! Form::model(\$editableItem, ['route' => ['items.update', \$editableItem->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::submit(trans('item.update'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @endif -@if (Request::get('action') == 'delete' && \$editableMaster) +@if (Request::get('action') == 'delete' && \$editableItem)
-

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

+

{{ trans('item.delete') }}

- -

{{ \$editableMaster->name }}

- {!! \$errors->first('master_id', ':message') !!} + +

{{ \$editableItem->name }}

+ {!! \$errors->first('item_id', ':message') !!}

{{ trans('app.delete_confirm') }}
- {!! FormField::delete(['route'=>['masters.destroy',\$editableMaster->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['master_id' => \$editableMaster->id]) !!} - {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! FormField::delete(['route'=>['items.destroy',\$editableItem->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['item_id' => \$editableItem->id]) !!} + {{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
@endif