質問編集履歴
3
試してみたこと2を追記。エラー画像削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,7 @@
|
|
124
124
|
|
125
125
|
|
126
126
|
|
127
|
-
##試し
|
127
|
+
##試してみたこと1
|
128
128
|
|
129
129
|
参考サイトなどをみて、「Player_no_check.php」のようにバリデーションルールを作成したつもりでしたが
|
130
130
|
|
@@ -260,14 +260,106 @@
|
|
260
260
|
|
261
261
|
|
262
262
|
|
263
|
+
##試してみたこと2
|
264
|
+
|
265
|
+
|
266
|
+
|
263
|
-
|
267
|
+
下記の記述を試したところ「syntax error, unexpected ';', expecting ']'」が表示されました。
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
+
|
268
|
-
|
269
|
-
|
269
|
+
```Player_no_check.php
|
270
|
-
|
271
|
-
|
272
|
-
|
270
|
+
|
273
|
-
|
271
|
+
public function passes($attribute, $value)
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
return [
|
276
|
+
|
277
|
+
'player_no' => Player::where('player_no',$value)
|
278
|
+
|
279
|
+
->where('team_owner_id', 1)
|
280
|
+
|
281
|
+
->doesntExist();
|
282
|
+
|
283
|
+
];
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
```
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
下記に変更をすると「syntax error」はなくなりましたが記述が合っているか自信がありません。
|
292
|
+
|
293
|
+
```Player_no_check.php
|
294
|
+
|
295
|
+
public function passes($attribute, $value)
|
296
|
+
|
297
|
+
{
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
return [
|
302
|
+
|
303
|
+
'player_no' => Player::where('player_no', $value)
|
304
|
+
|
305
|
+
->where('team_owner_id', 1)->doesntExist(), //「;」を「,」に変更
|
306
|
+
|
307
|
+
];
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
```PlayerController
|
314
|
+
|
315
|
+
public function store(Request $request)
|
316
|
+
|
317
|
+
{
|
318
|
+
|
319
|
+
$request->validate([
|
320
|
+
|
321
|
+
'player_no' => [new Player_no_check],
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
]);
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
$player = new Player();
|
330
|
+
|
331
|
+
$player->team_owner_id = Auth::id();
|
332
|
+
|
333
|
+
$player->player_no = $request->player_no;
|
334
|
+
|
335
|
+
$player->player_name = $request->player_name;
|
336
|
+
|
337
|
+
$player->save();
|
338
|
+
|
339
|
+
// dd($player);
|
340
|
+
|
341
|
+
return redirect()
|
342
|
+
|
343
|
+
->route('team_owner.players.index')
|
344
|
+
|
345
|
+
->with([
|
346
|
+
|
347
|
+
'message' => '選手登録をしました。',
|
348
|
+
|
349
|
+
'status' => 'info'
|
350
|
+
|
351
|
+
]);
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
この状態で選手の新規登録をおこないました。
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
結果としては、登録がなんでもできてしまいバリデーションが効いていないような感じになっています。
|
364
|
+
|
365
|
+
現在のteam_owner_idが1、player_noを10として何度も登録ができてしまう状態です。
|
2
エラー画像を追加12/8 13:07
test
CHANGED
File without changes
|
test
CHANGED
@@ -262,128 +262,12 @@
|
|
262
262
|
|
263
263
|
C:\xampp\htdocs\fifa_app\vendor\laravel\framework\src\Illuminate\Validation\ValidationRuleParser.php:114
|
264
264
|
|
265
|
+
|
266
|
+
|
265
|
-
|
267
|
+
エラー画像
|
266
|
-
|
267
|
-
|
268
|
+
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
*/
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
protected function prepareRule($rule)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
{
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
269
|
+
今私がエラーがでましたと言ってみている画像は下記になります。
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
270
|
+
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
271
|
+
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
272
|
+
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
$rule instanceof RuleContract ||
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
($rule instanceof Exists && $rule->queryCallbacks()) ||
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
($rule instanceof Unique && $rule->queryCallbacks())) {
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
return $rule;
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
273
|
+
![イメージ説明](2fdcf7fae30261ac43cb9fb5020ba446.jpeg)
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
/**
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
* Define a set of rules that apply to each element in an array attribute.
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
*
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
* @param array $results
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
* @param string $attribute
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
* @param string|array $rules
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
* @return array
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
*/
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
protected function explodeWildcardRules($results, $attribute, $rules)
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
{
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
$pattern = str_replace('*', '[^.]*', preg_quote($attribute));
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
$data = ValidationData::initializeAndGatherData($attribute, $this->data);
|
388
|
-
|
389
|
-
```
|
1
現在進行中の内容を追記12/8
test
CHANGED
File without changes
|
test
CHANGED
@@ -141,3 +141,249 @@
|
|
141
141
|
|
142
142
|
|
143
143
|
どうぞよろしくお願いいたします。
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
##現在でているエラー内容
|
148
|
+
|
149
|
+
修正後の記述
|
150
|
+
|
151
|
+
```player_no_check.php
|
152
|
+
|
153
|
+
namespace App\Rules;
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// use Illuminate\Contracts\Validation\Rule;
|
158
|
+
|
159
|
+
use Illuminate\Validation\Rule;
|
160
|
+
|
161
|
+
use App\Models\Team_owner;
|
162
|
+
|
163
|
+
use App\Models\Player;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
class Player_no_check extends Rule
|
172
|
+
|
173
|
+
{
|
174
|
+
|
175
|
+
/**
|
176
|
+
|
177
|
+
* Create a new rule instance.
|
178
|
+
|
179
|
+
*
|
180
|
+
|
181
|
+
* @return void
|
182
|
+
|
183
|
+
*/
|
184
|
+
|
185
|
+
public function __construct()
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
//
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
/**
|
196
|
+
|
197
|
+
* Determine if the validation rule passes.
|
198
|
+
|
199
|
+
*
|
200
|
+
|
201
|
+
* @param string $attribute
|
202
|
+
|
203
|
+
* @param mixed $value
|
204
|
+
|
205
|
+
* @return bool
|
206
|
+
|
207
|
+
*/
|
208
|
+
|
209
|
+
public function passes($attribute, $value)
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
dd($attribute, $value);
|
214
|
+
|
215
|
+
return [
|
216
|
+
|
217
|
+
'player_no' => Rule::unique('players')->where(function ($query) {
|
218
|
+
|
219
|
+
return $query->where('team_owner_id', 1);
|
220
|
+
|
221
|
+
})
|
222
|
+
|
223
|
+
];
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
/**
|
230
|
+
|
231
|
+
* Get the validation error message.
|
232
|
+
|
233
|
+
*
|
234
|
+
|
235
|
+
* @return string
|
236
|
+
|
237
|
+
*/
|
238
|
+
|
239
|
+
public function message()
|
240
|
+
|
241
|
+
{
|
242
|
+
|
243
|
+
return 'The validation error message.';
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```エラー
|
254
|
+
|
255
|
+
Error
|
256
|
+
|
257
|
+
Object of class App\Rules\Player_no_check could not be converted to string
|
258
|
+
|
259
|
+
```
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
C:\xampp\htdocs\fifa_app\vendor\laravel\framework\src\Illuminate\Validation\ValidationRuleParser.php:114
|
264
|
+
|
265
|
+
```エラー場所コード
|
266
|
+
|
267
|
+
* @return mixed
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
*/
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
protected function prepareRule($rule)
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
{
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if ($rule instanceof Closure) {
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
$rule = new ClosureValidationRule($rule);
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
if (! is_object($rule) ||
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
$rule instanceof RuleContract ||
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
($rule instanceof Exists && $rule->queryCallbacks()) ||
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
($rule instanceof Unique && $rule->queryCallbacks())) {
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
return $rule;
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
return (string) $rule; //ここでエラーがでている
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
/**
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
* Define a set of rules that apply to each element in an array attribute.
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
*
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
* @param array $results
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
* @param string $attribute
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
* @param string|array $rules
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
* @return array
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
*/
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
protected function explodeWildcardRules($results, $attribute, $rules)
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
{
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
$pattern = str_replace('*', '[^.]*', preg_quote($attribute));
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
$data = ValidationData::initializeAndGatherData($attribute, $this->data);
|
388
|
+
|
389
|
+
```
|