質問編集履歴
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,233 +9,3 @@
|
|
9
9
|
どのように修正すれば実現できるか教えていただきたいです。
|
10
10
|
|
11
11
|
よろしくお願いいたします。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
**menuテーブル**
|
20
|
-
|
21
|
-
|id|code|
|
22
|
-
|
23
|
-
|:--|:--:|
|
24
|
-
|
25
|
-
|1|A100||
|
26
|
-
|
27
|
-
|2|B100||
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
### 該当のソースコード
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
**web.php**
|
38
|
-
|
39
|
-
```php
|
40
|
-
|
41
|
-
Route::get('/menu/edit/{code}', [MenuController::class, 'edit'])->name('menu.edit');
|
42
|
-
|
43
|
-
Route::post('/menu/update/{code}', [MenuController::class, 'update'])->name('menu.update');
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
**コントローラー**
|
50
|
-
|
51
|
-
```php
|
52
|
-
|
53
|
-
public function update(UpdateAction $action, UpdateRequest $request, $code)
|
54
|
-
|
55
|
-
{
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
$storePattern = $action($request, $code);
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return redirect()->route('menu.edit', $request->code);
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
```
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
**更新処理クラス**
|
74
|
-
|
75
|
-
```ここに言語を入力
|
76
|
-
|
77
|
-
<?php
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
class UpdateAction
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
public function __invoke(Request $request, $storePatternCd)
|
86
|
-
|
87
|
-
{
|
88
|
-
|
89
|
-
DB::transaction(function () use ($request, $code) {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
Menu::where('code', $code)->update([
|
94
|
-
|
95
|
-
'code' => $request->code,
|
96
|
-
|
97
|
-
]);
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
});
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
```
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
**Requestクラス**
|
114
|
-
|
115
|
-
```php
|
116
|
-
|
117
|
-
<?php
|
118
|
-
|
119
|
-
class UpdateRequest extends FormRequest
|
120
|
-
|
121
|
-
{
|
122
|
-
|
123
|
-
/**
|
124
|
-
|
125
|
-
* Determine if the user is authorized to make this request.
|
126
|
-
|
127
|
-
*
|
128
|
-
|
129
|
-
* @return bool
|
130
|
-
|
131
|
-
*/
|
132
|
-
|
133
|
-
public function authorize()
|
134
|
-
|
135
|
-
{
|
136
|
-
|
137
|
-
return true;
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
/**
|
144
|
-
|
145
|
-
* Get the validation rules that apply to the request.
|
146
|
-
|
147
|
-
*
|
148
|
-
|
149
|
-
* @return array
|
150
|
-
|
151
|
-
*/
|
152
|
-
|
153
|
-
public function rules() {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
return [
|
158
|
-
|
159
|
-
'code' => ['required', Rule::unique('menus')->ignore($this->id)],
|
160
|
-
|
161
|
-
];
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
public function messages() {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
return [
|
172
|
-
|
173
|
-
'code.unique' => 'CDは既に登録されています',
|
174
|
-
|
175
|
-
];
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
```
|
184
|
-
|
185
|
-
**マイグレーション**
|
186
|
-
|
187
|
-
```
|
188
|
-
|
189
|
-
<?php
|
190
|
-
|
191
|
-
class MenuTable extends Migration
|
192
|
-
|
193
|
-
{
|
194
|
-
|
195
|
-
/**
|
196
|
-
|
197
|
-
* Run the migrations.
|
198
|
-
|
199
|
-
*
|
200
|
-
|
201
|
-
* @return void
|
202
|
-
|
203
|
-
*/
|
204
|
-
|
205
|
-
public function up()
|
206
|
-
|
207
|
-
{
|
208
|
-
|
209
|
-
Schema::create('menus', function (Blueprint $table) {
|
210
|
-
|
211
|
-
$table->id();
|
212
|
-
|
213
|
-
$table->string('code', 10)->unique()->comment('メニューコード');
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
/**
|
220
|
-
|
221
|
-
* Reverse the migrations.
|
222
|
-
|
223
|
-
*
|
224
|
-
|
225
|
-
* @return void
|
226
|
-
|
227
|
-
*/
|
228
|
-
|
229
|
-
public function down()
|
230
|
-
|
231
|
-
{
|
232
|
-
|
233
|
-
Schema::dropIfExists('menus');
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
```
|