Skip to content

Commit 2c6623d

Browse files
Correct form request name (#720)
1 parent 5e673af commit 2c6623d

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/Generators/ControllerGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function buildMethods(Controller $controller): string
128128
}
129129
} elseif ($statement instanceof ValidateStatement) {
130130
$using_validation = true;
131-
$class_name = $controller->name() . Str::studly($name) . 'Request';
131+
$class_name = Str::singular($controller->prefix()) . Str::studly($name) . 'Request';
132132

133133
$fqcn = config('blueprint.namespace') . '\\Http\\Requests\\' . ($controller->namespace() ? $controller->namespace() . '\\' : '') . $class_name;
134134

tests/Feature/Generators/ControllerGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public static function controllerTreeDataProvider(): array
239239
['drafts/readme-example-notification-facade.yaml', 'app/Http/Controllers/PostController.php', 'controllers/readme-example-notification-facade.php'],
240240
['drafts/readme-example-notification-model.yaml', 'app/Http/Controllers/PostController.php', 'controllers/readme-example-notification-model.php'],
241241
['drafts/crazy-eloquent.yaml', 'app/Http/Controllers/PostController.php', 'controllers/crazy-eloquent.php'],
242+
['drafts/longhand-controller-name.yaml', 'app/Http/Controllers/UserController.php', 'controllers/longhand-controller-name.php'],
242243
['drafts/nested-components.yaml', 'app/Http/Controllers/Admin/UserController.php', 'controllers/nested-components.php'],
243244
['drafts/respond-statements.yaml', 'app/Http/Controllers/Api/PostController.php', 'controllers/respond-statements.php'],
244245
['drafts/resource-statements.yaml', 'app/Http/Controllers/UserController.php', 'controllers/resource-statements.php'],
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Requests\UserStoreRequest;
6+
use App\Http\Requests\UserUpdateRequest;
7+
use App\Models\User;
8+
use Illuminate\Http\RedirectResponse;
9+
use Illuminate\Http\Request;
10+
11+
class UserController extends Controller
12+
{
13+
public function store(UserStoreRequest $request): RedirectResponse
14+
{
15+
$user = User::create($request->validated());
16+
17+
return redirect()->route('backend.users.show');
18+
}
19+
20+
public function update(UserUpdateRequest $request, User $user): RedirectResponse
21+
{
22+
$user->update($request->validated());
23+
24+
$request->session()->flash('user.id', $user->id);
25+
26+
return redirect()->route('user.index');
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
controllers:
2+
UserController:
3+
store:
4+
validate: user
5+
save: user
6+
redirect: backend.users.show
7+
update:
8+
validate: user
9+
update: user
10+
flash: user.id
11+
redirect: user.index

0 commit comments

Comments
 (0)