teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

カスタムリクエストを追記

2018/05/21 04:49

投稿

motuo
motuo

スコア3027

answer CHANGED
@@ -9,4 +9,45 @@
9
9
  })
10
10
  ],
11
11
  ])->validate();
12
+ ```
13
+
14
+ # 追記
15
+ 私の環境ではこのカスタムリクエストクラスで動かせました。
16
+ ```php
17
+ <?php
18
+
19
+ namespace App\Http\Requests;
20
+
21
+ use Illuminate\Foundation\Http\FormRequest;
22
+ use Illuminate\Validation\Rule;
23
+ use Illuminate\Http\Request;
24
+
25
+ class TaskRequest extends FormRequest
26
+ {
27
+ /**
28
+ * Determine if the user is authorized to make this request.
29
+ *
30
+ * @return bool
31
+ */
32
+ public function authorize()
33
+ {
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * Get the validation rules that apply to the request.
39
+ *
40
+ * @return array
41
+ */
42
+ public function rules(Request $request)
43
+ {
44
+ return [
45
+ 'task_list_id2' =>
46
+ Rule::unique('tests')->where(function($query) use($request){
47
+ return $query->where("task_list_id",$request->task_list_id);
48
+ })
49
+ ];
50
+ }
51
+ }
52
+
12
53
  ```