回答編集履歴

1

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

2018/05/21 04:49

投稿

motuo
motuo

スコア3027

test CHANGED
@@ -21,3 +21,85 @@
21
21
  ])->validate();
22
22
 
23
23
  ```
24
+
25
+
26
+
27
+ # 追記
28
+
29
+ 私の環境ではこのカスタムリクエストクラスで動かせました。
30
+
31
+ ```php
32
+
33
+ <?php
34
+
35
+
36
+
37
+ namespace App\Http\Requests;
38
+
39
+
40
+
41
+ use Illuminate\Foundation\Http\FormRequest;
42
+
43
+ use Illuminate\Validation\Rule;
44
+
45
+ use Illuminate\Http\Request;
46
+
47
+
48
+
49
+ class TaskRequest extends FormRequest
50
+
51
+ {
52
+
53
+ /**
54
+
55
+ * Determine if the user is authorized to make this request.
56
+
57
+ *
58
+
59
+ * @return bool
60
+
61
+ */
62
+
63
+ public function authorize()
64
+
65
+ {
66
+
67
+ return true;
68
+
69
+ }
70
+
71
+
72
+
73
+ /**
74
+
75
+ * Get the validation rules that apply to the request.
76
+
77
+ *
78
+
79
+ * @return array
80
+
81
+ */
82
+
83
+ public function rules(Request $request)
84
+
85
+ {
86
+
87
+ return [
88
+
89
+ 'task_list_id2' =>
90
+
91
+ Rule::unique('tests')->where(function($query) use($request){
92
+
93
+ return $query->where("task_list_id",$request->task_list_id);
94
+
95
+ })
96
+
97
+ ];
98
+
99
+ }
100
+
101
+ }
102
+
103
+
104
+
105
+ ```