質問編集履歴

1

試行錯誤した記録を追加

2019/09/17 02:29

投稿

shoco
shoco

スコア148

test CHANGED
File without changes
test CHANGED
@@ -120,10 +120,64 @@
120
120
 
121
121
 
122
122
 
123
- コーディング簡略化に自信のある人がいましたら
123
+ ```
124
124
 
125
+ 試行錯誤内容としましては
126
+
127
+ ```
128
+
129
+ ・既存のFormRequestクラスのfailedValidationメソッドを下のように変えても
130
+
131
+
132
+
133
+ protected function failedValidation(Validator $validator)
134
+
135
+ {
136
+
137
+ throw (new ValidationException($validator))
138
+
139
+ ->errorBag($this->errorBag)
140
+
141
+ ->redirectTo($this->getRedirectUrl());
142
+
143
+ }
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+ protected function failedValidation(Validator $validator)
152
+
153
+ {
154
+
155
+ $response['code'] = 'XXX';
156
+
157
+
158
+
159
+ if($validator->errors()->has($xxxxxxxxx)) {
160
+
161
+ $response['message'] = $validator->errors()->first($xxxxxxxxx);
162
+
163
+ throw new HttpResponseException(response()->json($response, 422));
164
+
165
+ }
166
+
167
+ }
168
+
169
+ $xxxxxxxxxの箇所を汎用的に使用できる変数にして
170
+
171
+ この部品だけですべてのすべてのバリデーション処理ができるようにさせたい
172
+
125
- よろ願いします。
173
+ と色々試ます。
126
174
 
127
175
 
128
176
 
129
177
  ```
178
+
179
+
180
+
181
+ コーディング簡略化に自信のある人がいましたら
182
+
183
+ よろしくお願いします。