diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index e6675553..03450be3 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -128,7 +128,7 @@ protected function buildMethods(Controller $controller): string } } elseif ($statement instanceof ValidateStatement) { $using_validation = true; - $class_name = $controller->name() . Str::studly($name) . 'Request'; + $class_name = Str::singular($controller->prefix()) . Str::studly($name) . 'Request'; $fqcn = config('blueprint.namespace') . '\\Http\\Requests\\' . ($controller->namespace() ? $controller->namespace() . '\\' : '') . $class_name; diff --git a/tests/Feature/Generators/ControllerGeneratorTest.php b/tests/Feature/Generators/ControllerGeneratorTest.php index 5a438f35..aaae3210 100644 --- a/tests/Feature/Generators/ControllerGeneratorTest.php +++ b/tests/Feature/Generators/ControllerGeneratorTest.php @@ -239,6 +239,7 @@ public static function controllerTreeDataProvider(): array ['drafts/readme-example-notification-facade.yaml', 'app/Http/Controllers/PostController.php', 'controllers/readme-example-notification-facade.php'], ['drafts/readme-example-notification-model.yaml', 'app/Http/Controllers/PostController.php', 'controllers/readme-example-notification-model.php'], ['drafts/crazy-eloquent.yaml', 'app/Http/Controllers/PostController.php', 'controllers/crazy-eloquent.php'], + ['drafts/longhand-controller-name.yaml', 'app/Http/Controllers/UserController.php', 'controllers/longhand-controller-name.php'], ['drafts/nested-components.yaml', 'app/Http/Controllers/Admin/UserController.php', 'controllers/nested-components.php'], ['drafts/respond-statements.yaml', 'app/Http/Controllers/Api/PostController.php', 'controllers/respond-statements.php'], ['drafts/resource-statements.yaml', 'app/Http/Controllers/UserController.php', 'controllers/resource-statements.php'], diff --git a/tests/fixtures/controllers/longhand-controller-name.php b/tests/fixtures/controllers/longhand-controller-name.php new file mode 100644 index 00000000..2f3e8b66 --- /dev/null +++ b/tests/fixtures/controllers/longhand-controller-name.php @@ -0,0 +1,28 @@ +validated()); + + return redirect()->route('backend.users.show'); + } + + public function update(UserUpdateRequest $request, User $user): RedirectResponse + { + $user->update($request->validated()); + + $request->session()->flash('user.id', $user->id); + + return redirect()->route('user.index'); + } +} diff --git a/tests/fixtures/drafts/longhand-controller-name.yaml b/tests/fixtures/drafts/longhand-controller-name.yaml new file mode 100644 index 00000000..84163a6c --- /dev/null +++ b/tests/fixtures/drafts/longhand-controller-name.yaml @@ -0,0 +1,11 @@ +controllers: + UserController: + store: + validate: user + save: user + redirect: backend.users.show + update: + validate: user + update: user + flash: user.id + redirect: user.index