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

質問編集履歴

2

回答を基に試した結果を追加

2018/05/21 04:06

投稿

sabamiso
sabamiso

スコア14

title CHANGED
File without changes
body CHANGED
@@ -133,4 +133,46 @@
133
133
  下記の記事等を参考にさせていただきましたが、実現できませんでした。
134
134
  [http://tdsen.blog.jp/archives/33449990.html](http://tdsen.blog.jp/archives/33449990.html)
135
135
 
136
- 初歩的な質問なのかもしれませんが、有識者の方、何卒お力添えをよろしくお願いいたします。
136
+ 初歩的な質問なのかもしれませんが、有識者の方、何卒お力添えをよろしくお願いいたします。
137
+
138
+ ### 補足情報
139
+ 下記のバリデーションを設定した場合、エラーが発生しました。
140
+ ```php
141
+ <?php
142
+
143
+ namespace App\Http\Requests;
144
+
145
+ use Illuminate\Foundation\Http\FormRequest;
146
+ use Illuminate\Validation\Rule;
147
+ use App\Http\Requests\TaskRequest;
148
+
149
+ class TaskRequest extends FormRequest
150
+ {
151
+ /**
152
+ * Determine if the user is authorized to make this request.
153
+ *
154
+ * @return bool
155
+ */
156
+ public function authorize()
157
+ {
158
+ return true;
159
+ }
160
+
161
+ public function rules()
162
+ {
163
+ return [
164
+ Validator::make($data, [
165
+ 'task_name' =>[
166
+ Rule::unique('tasks')->where(function ($query){
167
+ return $query->where('task_list_id', $data['task_list_id']);
168
+ })
169
+ ],
170
+ ]->validate();
171
+ ];
172
+ }
173
+ ```
174
+
175
+ ```
176
+ ReflectionException
177
+ Class App\Http\Requests\TaskRequest does not exist
178
+ ```

1

Viewのコードを追加しました。

2018/05/21 04:05

投稿

sabamiso
sabamiso

スコア14

title CHANGED
File without changes
body CHANGED
@@ -63,6 +63,19 @@
63
63
  }
64
64
  ```
65
65
 
66
+ viewのタスク追加フォーム
67
+ ```php
68
+ <form method="post" action="{{ action('TaskController@store', $list) }}" >
69
+ {{ csrf_field() }}
70
+ <div class="form-group">
71
+ <label for="nameInput">タスク名</label>
72
+ <input type="text" class="form-control" id="nameInput" name="task_name">
73
+ <input type="date" class="form-control" id="limitInput" name="limit">
74
+ </div>
75
+ <button type="submit" class="btn btn-primary">新規追加</button>
76
+ </form>
77
+ ```
78
+
66
79
  **実現したいこと**
67
80
 
68
81
  タスクリスト内のタスクを追加する際、タスクリスト内でのみタスク名の重複を禁止したい。