diff --git a/src/CrudMake.php b/src/CrudMake.php index 16e7a75..b7bd5cb 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -141,55 +141,55 @@ class CrudMake extends Command public function getControllerContent() { $stub = $this->files->get(__DIR__.'/stubs/controller.model.stub'); - return $this->replaceControllerDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } private function getMigrationContent() { $stub = $this->files->get(__DIR__.'/stubs/migration-create.stub'); - return $this->replaceMigrationDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getIndexViewContent() { $stub = $this->files->get(__DIR__.'/stubs/view-index.stub'); - return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getFormsViewContent() { $stub = $this->files->get(__DIR__.'/stubs/view-forms.stub'); - return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getLangFileContent() { $stub = $this->files->get(__DIR__.'/stubs/lang.stub'); - return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getModelFactoryContent() { $stub = $this->files->get(__DIR__.'/stubs/model-factory.stub'); - return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getFeatureTestContent() { $stub = $this->files->get(__DIR__.'/stubs/test.stub'); - return $this->replaceFeatureTestDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getUnitTestContent() { $stub = $this->files->get(__DIR__.'/stubs/unit-test.stub'); - return $this->replaceUnitTestDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } public function getWebRouteContent() { $stub = $this->files->get(__DIR__.'/stubs/route-web.stub'); - return $this->replaceViewDummyStrings($stub)->replaceClass($stub); + return $this->replaceStubString($stub); } protected function makeDirectory($path) @@ -214,66 +214,15 @@ class CrudMake extends Command return $routeDirPath.'/'.$filename; } - protected function replaceControllerDummyStrings(&$stub) + protected function replaceStubString($stub) { $stub = str_replace( - ['master', 'Master'], - [$this->singleModelName, $this->modelName], + ['Masters', 'Master', 'master', 'masters'], + [$this->pluralModelName, $this->modelName, $this->singleModelName, $this->lowerCasePluralModel], $stub ); - return $this; - } - - protected function replaceFeatureTestDummyStrings(&$stub) - { - $stub = str_replace( - ['Masters'], - [$this->pluralModelName], - $stub - ); - - return $this; - } - - protected function replaceUnitTestDummyStrings(&$stub) - { - $stub = str_replace( - ['Master'], - [$this->modelName], - $stub - ); - - return $this; - } - - protected function replaceMigrationDummyStrings(&$stub) - { - $stub = str_replace( - ['masters', 'Masters'], - [$this->lowerCasePluralModel, $this->pluralModelName], - $stub - ); - - return $this; - } - - protected function replaceViewDummyStrings(&$stub) - { - $stub = str_replace( - ['Master', 'master', 'masters'], - [$this->modelName, $this->singleModelName, $this->lowerCasePluralModel], - $stub - ); - - return $this; - } - - protected function replaceClass($stub) - { - $class = str_plural($this->modelName); - - return str_replace('DummyClass', $class, $stub); + return $stub; } protected function getNamespace($name) diff --git a/src/stubs/controller.model.stub b/src/stubs/controller.model.stub index acff50e..87aaa0c 100644 --- a/src/stubs/controller.model.stub +++ b/src/stubs/controller.model.stub @@ -6,7 +6,7 @@ use App\Master; use Illuminate\Http\Request; use App\Http\Controllers\Controller; -class DummyClassController extends Controller +class MastersController extends Controller { /** * Display a listing of the resource.