From 7c1ed11bcea81c54045cb668c9c29312c9ddde78 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 11 Feb 2018 13:39:37 +0800 Subject: [PATCH] Fixed after make:crud (full) usage failure on laravel 5.5 --- src/GeneratorCommand.php | 1 + src/stubs/controller.full.stub | 4 ++-- src/stubs/view-index-full.stub | 2 +- tests/Generators/FullControllerGeneratorTest.php | 12 ++++++------ tests/Generators/ViewsGeneratorTest.php | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/GeneratorCommand.php b/src/GeneratorCommand.php index 9e9cd17..c33ff95 100644 --- a/src/GeneratorCommand.php +++ b/src/GeneratorCommand.php @@ -102,6 +102,7 @@ class GeneratorCommand extends Command { $appNamespace = trim($this->getAppNamespace(), '\\'); $modelNamespace = str_replace('/', '\\', $appNamespace.'/'.ucfirst($modelPath)); + $modelNamespace = trim($modelNamespace, '\\'); return $modelNamespace == 'App\\' ? 'App' : $modelNamespace; } diff --git a/src/stubs/controller.full.stub b/src/stubs/controller.full.stub index 03d32b1..0d43fd2 100644 --- a/src/stubs/controller.full.stub +++ b/src/stubs/controller.full.stub @@ -51,9 +51,9 @@ class MastersController extends Controller 'description' => 'nullable|max:255', ]); - Master::create($request->only('name', 'description')); + $singleMstr = Master::create($request->only('name', 'description')); - return redirect()->route('masters.index'); + return redirect()->route('masters.show', $singleMstr); } /** diff --git a/src/stubs/view-index-full.stub b/src/stubs/view-index-full.stub index bacad5b..90a99fb 100644 --- a/src/stubs/view-index-full.stub +++ b/src/stubs/view-index-full.stub @@ -6,7 +6,7 @@

@can('create', new fullMstr) - {{ link_to_route('masters.index', trans('master.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} + {{ link_to_route('masters.create', trans('master.create'), [], ['class' => 'btn btn-success']) }} @endcan
{{ trans('master.list') }} diff --git a/tests/Generators/FullControllerGeneratorTest.php b/tests/Generators/FullControllerGeneratorTest.php index e3280e2..8219b21 100644 --- a/tests/Generators/FullControllerGeneratorTest.php +++ b/tests/Generators/FullControllerGeneratorTest.php @@ -65,9 +65,9 @@ class {$this->plural_model_name}Controller extends Controller 'description' => 'nullable|max:255', ]); - {$this->model_name}::create(\$request->only('name', 'description')); + \${$this->single_model_var_name} = {$this->model_name}::create(\$request->only('name', 'description')); - return redirect()->route('{$this->table_name}.index'); + return redirect()->route('{$this->table_name}.show', \${$this->single_model_var_name}); } /** @@ -201,9 +201,9 @@ class CategoriesController extends Controller 'description' => 'nullable|max:255', ]); - Category::create(\$request->only('name', 'description')); + \$category = Category::create(\$request->only('name', 'description')); - return redirect()->route('categories.index'); + return redirect()->route('categories.show', \$category); } /** @@ -338,9 +338,9 @@ class CategoriesController extends Controller 'description' => 'nullable|max:255', ]); - Category::create(\$request->only('name', 'description')); + \$category = Category::create(\$request->only('name', 'description')); - return redirect()->route('categories.index'); + return redirect()->route('categories.show', \$category); } /** diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index 5eac3c2..c73c0a9 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -22,7 +22,7 @@ class ViewsGeneratorTest extends TestCase

@can('create', new {$this->full_model_name}) - {{ link_to_route('{$this->table_name}.index', trans('{$this->lang_name}.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} + {{ link_to_route('{$this->table_name}.create', trans('{$this->lang_name}.create'), [], ['class' => 'btn btn-success']) }} @endcan
{{ trans('{$this->lang_name}.list') }}