diff --git a/src/CrudMake.php b/src/CrudMake.php index e480a11..3931ee9 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -88,12 +88,16 @@ class CrudMake extends Command public function getModelName($modelName = null) { $modelName = is_null($modelName) ? $this->argument('name') : $modelName; + $model_name = ucfirst($modelName); + $plural_model_name = str_plural($model_name); return $this->modelNames = [ - 'plural_model_name' => str_plural($modelName), - 'model_name' => $modelName, - 'lowercase_plural_model_name' => strtolower(str_plural($modelName)), - 'lowercase_single_model_name' => strtolower($modelName), + 'plural_model_name' => $plural_model_name, + 'model_name' => $model_name, + 'table_name' => snake_case($plural_model_name), + 'lang_name' => snake_case($model_name), + 'collection_model_var_name' => camel_case($plural_model_name), + 'single_model_var_name' => camel_case($model_name), ]; } @@ -142,7 +146,7 @@ class CrudMake extends Command public function generateMigration() { $prefix = date('Y_m_d_His'); - $tableName = $this->modelNames['lowercase_plural_model_name']; + $tableName = $this->modelNames['table_name']; $migrationPath = $this->makeDirectory(database_path('migrations')); @@ -159,7 +163,7 @@ class CrudMake extends Command */ public function generateViews() { - $viewPath = $this->makeDirectory(resource_path('views/'.$this->modelNames['lowercase_plural_model_name'])); + $viewPath = $this->makeDirectory(resource_path('views/'.$this->modelNames['table_name'])); $this->generateFile($viewPath.'/index.blade.php', $this->getIndexViewContent()); $this->generateFile($viewPath.'/forms.blade.php', $this->getFormsViewContent()); @@ -176,9 +180,9 @@ class CrudMake extends Command { $langPath = $this->makeDirectory(resource_path('lang/en')); - $this->generateFile($langPath.'/'.$this->modelNames['lowercase_single_model_name'].'.php', $this->getLangFileContent()); + $this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getLangFileContent()); - $this->info($this->modelNames['lowercase_single_model_name'].' lang files generated.'); + $this->info($this->modelNames['lang_name'].' lang files generated.'); } /** @@ -195,7 +199,7 @@ class CrudMake extends Command $this->getModelFactoryContent() ); - $this->info($this->modelNames['lowercase_single_model_name'].' model factory generated.'); + $this->info($this->modelNames['lang_name'].' model factory generated.'); } /** diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index bcdc2f4..7ab6906 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -25,9 +25,11 @@ class CrudMakeCommandTest extends TestCase $this->assertEquals([ 'plural_model_name' => 'Categories', 'model_name' => 'Category', - 'lowercase_plural_model_name' => 'categories', - 'lowercase_single_model_name' => 'category', - ], $crudMaker->getModelName('Category')); + 'table_name' => 'categories', + 'lang_name' => 'category', + 'collection_model_var_name' => 'categories', + 'single_model_var_name' => 'category', + ], $crudMaker->getModelName('category')); } /** @test */ diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php index 3cbc953..23c480a 100644 --- a/tests/Generators/ControllerGeneratorTest.php +++ b/tests/Generators/ControllerGeneratorTest.php @@ -29,7 +29,7 @@ class {$this->plural_model_name}Controller extends Controller public function index() { \$editable{$this->model_name} = null; - \${$this->table_name} = {$this->model_name}::where(function (\$query) { + \${$this->collection_model_var_name} = {$this->model_name}::where(function (\$query) { \$query->where('name', 'like', '%'.request('q').'%'); })->paginate(25); diff --git a/tests/Generators/LangGeneratorTest.php b/tests/Generators/LangGeneratorTest.php index d1771d6..5c6b4c9 100644 --- a/tests/Generators/LangGeneratorTest.php +++ b/tests/Generators/LangGeneratorTest.php @@ -11,13 +11,13 @@ class LangGeneratorTest extends TestCase { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); - $langPath = resource_path('lang/en/'.$this->single_model_var_name.'.php'); + $langPath = resource_path('lang/en/'.$this->lang_name.'.php'); $this->assertFileExists($langPath); $langFileContent = "single_model_var_name}' => '{$this->model_name}', + '{$this->lang_name}' => '{$this->model_name}', 'list' => '{$this->model_name} List', 'search' => 'Search {$this->model_name}', 'not_found' => '{$this->model_name} not found.', diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index 587bab8..5e8623a 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -15,23 +15,23 @@ class ViewsGeneratorTest extends TestCase $this->assertFileExists($indexViewPath); $indexViewContent = "@extends('layouts.app') -@section('title', trans('{$this->single_model_var_name}.list')) +@section('title', trans('{$this->lang_name}.list')) @section('content')
{{ \$editable{$this->model_name}->name }}
{!! \$errors->first('{$this->single_model_var_name}_id', ':message') !!}