質問編集履歴

10

コード修正

2018/07/19 06:27

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -70,11 +70,11 @@
70
70
 
71
71
  <ul>
72
72
 
73
- @foreach($errors->all() as $error)
73
+ @foreach($errors->all() as $error)
74
-
74
+
75
- <li>{{ $error }}</li>
75
+ <li>{{ $error }}</li>
76
-
76
+
77
- @endforeach
77
+ @endforeach
78
78
 
79
79
  </ul>
80
80
 
@@ -88,24 +88,24 @@
88
88
 
89
89
  <form action="{{ url('create') }}" method="POST" enctype="multipart/form-data">
90
90
 
91
- <label for="jan">Jan_Code:</label>
91
+ <label for="jan">Jan_Code:</label>
92
-
92
+
93
-   <input type="text" class="form-control" name="jan" value="{{old('jan')}}">
93
+ <input type="text" class="form-control" name="jan" value="{{old('jan')}}">
94
+
95
+ <br>
96
+
97
+ <label for="name">Item_name</label>
98
+
99
+ <input type="text" class="form-control" name="name" value="{{old('name')}}">
94
100
 
95
101
  <br>
96
102
 
97
- <label for="name">Item_name</label>
103
+ <label for="photo">Image_File(Multiple possible)</label>
98
-
104
+
99
- <input type="text" class="form-control" name="name" value="{{old('name')}}">
105
+ <input type="file" class="form-control" name="files[][photo]" multiple>
100
106
 
101
107
  <br>
102
108
 
103
- <label for="photo">Image_File(Multiple possible)</label>
104
-
105
- <input type="file" class="form-control" name="files[][photo]" multiple>
106
-
107
- <br>
108
-
109
109
  <hr>
110
110
 
111
111
  {{ csrf_field() }}
@@ -116,31 +116,31 @@
116
116
 
117
117
  <table class="table table-striped table-hover">
118
118
 
119
- <thead>
119
+ <thead>
120
-
120
+
121
- <tr>
121
+ <tr>
122
-
122
+
123
- <th>No</th>
123
+ <th>No</th>
124
-
124
+
125
- <th>name</th>
125
+ <th>name</th>
126
-
126
+
127
- </tr>
127
+ </tr>
128
-
128
+
129
- </thead>
129
+ </thead>
130
-
130
+
131
- <tbody>
131
+ <tbody>
132
132
 
133
133
    @foreach($ehime as $item)
134
134
 
135
135
    <tr>
136
136
 
137
-     <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
137
+ <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
138
138
 
139
139
    </tr>
140
140
 
141
141
    @endforeach
142
142
 
143
- </tbody>
143
+ </tbody>
144
144
 
145
145
  </table>
146
146
 
@@ -176,9 +176,9 @@
176
176
 
177
177
  {
178
178
 
179
-    $items = ItemPhoto::all();
179
+ $items = ItemPhoto::all();
180
-
180
+
181
-    return view('item.create')->with('ehime',$items);
181
+  return view('item.create')->with('ehime',$items);
182
182
 
183
183
  }
184
184
 
@@ -188,35 +188,35 @@
188
188
 
189
189
  {
190
190
 
191
-  // POST
191
+ // POST
192
-
192
+
193
-  if($request->isMethod('POST')) {
193
+ if($request->isMethod('POST')) {
194
-
194
+
195
-   // 商品情報の保存
195
+   // 商品情報の保存
196
-
196
+
197
-   $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
197
+   $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
198
-
198
+
199
-   // 商品画像の保存
199
+   // 商品画像の保存
200
-
200
+
201
-   foreach ($request->file('files') as $index=> $e) {
201
+ foreach ($request->file('files') as $index=> $e) {
202
-
202
+
203
-     $ext = $e['photo']->guessExtension();
203
+ $ext = $e['photo']->guessExtension();
204
-
204
+
205
-     $filename = "{$request->jan}_{$index}.{$ext}";
205
+   $filename = "{$request->jan}_{$index}.{$ext}";
206
-
206
+
207
-     $path = $e['photo']->storeAs('photos', $filename);
207
+   $path = $e['photo']->storeAs('photos', $filename);
208
-
208
+
209
-    // photosメソッドにより、商品に紐付けられた画像を保存する
209
+   // photosメソッドにより、商品に紐付けられた画像を保存する
210
-
210
+
211
-    $item->photos()->create(['path'=> $path]);
211
+   $item->photos()->create(['path'=> $path]);
212
-
212
+
213
- }
213
+ }
214
-
214
+
215
- return redirect()->action('ItemController@index');
215
+ return redirect()->action('ItemController@index');
216
216
 
217
217
  }
218
218
 
219
- // GET
219
+ // GET
220
220
 
221
221
  return view('item.create');
222
222
 
@@ -256,17 +256,17 @@
256
256
 
257
257
  {
258
258
 
259
-    if($this->isMethod('get')) return[];
259
+ if($this->isMethod('get')) return[];
260
-
260
+
261
-    return [
261
+  return [
262
-
262
+
263
-        'jan'=>'required',
263
+ 'jan'=>'required',
264
-
264
+
265
-        'name'=>'required',
265
+   'name'=>'required',
266
-
266
+
267
-        'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
267
+   'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
268
-
268
+
269
-    ];
269
+  ];
270
270
 
271
271
  }
272
272
 
@@ -276,15 +276,15 @@
276
276
 
277
277
  {
278
278
 
279
-   return [
279
+  return [
280
-
280
+
281
-        "required" => "Required items",
281
+ "required" => "Required items",
282
-
282
+
283
-        "image" => "Specified files is not image files!!",
283
+   "image" => "Specified files is not image files!!",
284
-
284
+
285
-        "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
285
+   "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
286
-
286
+
287
-   ];
287
+  ];
288
288
 
289
289
  }
290
290
 

9

追記

2018/07/19 06:27

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -22,10 +22,26 @@
22
22
 
23
23
  (Collectionクラスにrenderメソッドはない)
24
24
 
25
+
26
+
25
27
  <やったこと>
26
28
 
27
29
  $ehime->render()や$ehime->links()で試したがダメ
28
30
 
31
+
32
+
33
+ <参考サイト>
34
+
35
+ ①Laravelのvalidationメソッドでバリデーションを実装する入門編(日本語エラーメッセージ付き)
36
+
37
+ https://www.ritolab.com/entry/40
38
+
39
+ ②laravel5.5を使用して複数画像をアップロードする方法
40
+
41
+ https://qiita.com/netfish/items/ef01cdb5f58742563e87
42
+
43
+
44
+
29
45
  <記入内容>
30
46
 
31
47
  web.php

8

表記内容

2018/07/19 05:57

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -174,7 +174,7 @@
174
174
 
175
175
   // POST
176
176
 
177
-  if ($request->isMethod('POST')) {
177
+  if($request->isMethod('POST')) {
178
178
 
179
179
    // 商品情報の保存
180
180
 
@@ -194,19 +194,19 @@
194
194
 
195
195
     $item->photos()->create(['path'=> $path]);
196
196
 
197
+ }
198
+
199
+ return redirect()->action('ItemController@index');
200
+
197
201
  }
198
202
 
199
- return redirect()->action('ItemController@index');
200
-
201
- }
202
-
203
203
  // GET
204
204
 
205
205
  return view('item.create');
206
206
 
207
207
  }
208
208
 
209
-
209
+
210
210
 
211
211
  }
212
212
 

7

表記内容

2018/07/19 05:53

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -154,6 +154,8 @@
154
154
 
155
155
  class ItemController extends Controller{
156
156
 
157
+
158
+
157
159
  public function index()
158
160
 
159
161
  {
@@ -164,6 +166,8 @@
164
166
 
165
167
  }
166
168
 
169
+
170
+
167
171
  public function create(Request $request)
168
172
 
169
173
  {
@@ -200,7 +204,9 @@
200
204
 
201
205
  return view('item.create');
202
206
 
203
- }
207
+ }
208
+
209
+
204
210
 
205
211
  }
206
212
 
@@ -218,6 +224,8 @@
218
224
 
219
225
  class ItemRequest extends FormRequest{
220
226
 
227
+
228
+
221
229
  public function authorize()
222
230
 
223
231
  {
@@ -226,6 +234,8 @@
226
234
 
227
235
  }
228
236
 
237
+
238
+
229
239
  public function rules()
230
240
 
231
241
  {
@@ -244,6 +254,8 @@
244
254
 
245
255
  }
246
256
 
257
+
258
+
247
259
  public function messages()
248
260
 
249
261
  {
@@ -260,6 +272,8 @@
260
272
 
261
273
  }
262
274
 
275
+
276
+
263
277
  }
264
278
 
265
279
  ```

6

表記内容

2018/07/19 01:24

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -200,7 +200,7 @@
200
200
 
201
201
  return view('item.create');
202
202
 
203
- }
203
+ }
204
204
 
205
205
  }
206
206
 

5

表記内容

2018/07/19 01:23

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -154,110 +154,112 @@
154
154
 
155
155
  class ItemController extends Controller{
156
156
 
157
- public function index()
157
+ public function index()
158
-
158
+
159
- {
159
+ {
160
-
160
+
161
-   $items = ItemPhoto::all();
161
+    $items = ItemPhoto::all();
162
-
162
+
163
-   return view('item.create')->with('ehime',$items);
163
+    return view('item.create')->with('ehime',$items);
164
+
165
+ }
166
+
167
+ public function create(Request $request)
168
+
169
+ {
170
+
171
+  // POST
172
+
173
+  if ($request->isMethod('POST')) {
174
+
175
+   // 商品情報の保存
176
+
177
+   $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
178
+
179
+   // 商品画像の保存
180
+
181
+   foreach ($request->file('files') as $index=> $e) {
182
+
183
+     $ext = $e['photo']->guessExtension();
184
+
185
+     $filename = "{$request->jan}_{$index}.{$ext}";
186
+
187
+     $path = $e['photo']->storeAs('photos', $filename);
188
+
189
+    // photosメソッドにより、商品に紐付けられた画像を保存する
190
+
191
+    $item->photos()->create(['path'=> $path]);
192
+
193
+ }
194
+
195
+ return redirect()->action('ItemController@index');
196
+
197
+ }
198
+
199
+ // GET
200
+
201
+ return view('item.create');
202
+
203
+ }
164
204
 
165
205
  }
166
206
 
207
+ ```
208
+
209
+ バリデーション(ItemRequest.php)
210
+
211
+ ```
212
+
213
+ <?php
214
+
215
+ namespace App\Http\Requests;
216
+
217
+ use Illuminate\Foundation\Http\FormRequest;
218
+
219
+ class ItemRequest extends FormRequest{
220
+
167
- public function create(Request $request)
221
+ public function authorize()
168
-
222
+
169
- {
223
+ {
170
-
224
+
171
-   // POST
225
+ return true;
172
-
173
-   if ($request->isMethod('POST')) {
226
+
174
-
175
-   // 商品情報の保存
176
-
177
-   $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
178
-
179
-   // 商品画像の保存
180
-
181
-   foreach ($request->file('files') as $index=> $e) {
182
-
183
-     $ext = $e['photo']->guessExtension();
184
-
185
-     $filename = "{$request->jan}_{$index}.{$ext}";
186
-
187
-     $path = $e['photo']->storeAs('photos', $filename);
188
-
189
-    // photosメソッドにより、商品に紐付けられた画像を保存する
190
-
191
-    $item->photos()->create(['path'=> $path]);
192
-
193
-   }
227
+ }
228
+
194
-
229
+ public function rules()
230
+
231
+ {
232
+
233
+    if($this->isMethod('get')) return[];
234
+
235
+    return [
236
+
237
+        'jan'=>'required',
238
+
195
-   return redirect()->action('ItemController@index');
239
+        'name'=>'required',
240
+
196
-
241
+        'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
242
+
243
+    ];
244
+
197
-   }
245
+ }
198
-
246
+
199
-   // GET
247
+ public function messages()
248
+
200
-
249
+ {
250
+
251
+   return [
252
+
201
-   return view('item.create');
253
+        "required" => "Required items",
254
+
202
-
255
+        "image" => "Specified files is not image files!!",
256
+
257
+        "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
258
+
259
+   ];
260
+
203
-   }
261
+ }
204
262
 
205
263
  }
206
264
 
207
265
  ```
208
-
209
- バリデーション(ItemRequest.php)
210
-
211
- ```
212
-
213
- <?php
214
-
215
- namespace App\Http\Requests;
216
-
217
- use Illuminate\Foundation\Http\FormRequest;
218
-
219
- class ItemRequest extends FormRequest{
220
-
221
- public function authorize()
222
-
223
- {
224
-
225
- return true;
226
-
227
- }
228
-
229
- public function rules()
230
-
231
- {
232
-
233
-   if($this->isMethod('get')) return[];
234
-
235
-   return [
236
-
237
-        'jan'=>'required',
238
-
239
-        'name'=>'required',
240
-
241
-        'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
242
-
243
-   ];
244
-
245
- }
246
-
247
- public function messages()
248
-
249
- {
250
-
251
-   return [
252
-
253
-        "required" => "Required items",
254
-
255
-        "image" => "Specified files is not image files!!",
256
-
257
-        "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
258
-
259
-   ];
260
-
261
- }
262
-
263
- ```

4

表記内容

2018/07/19 01:06

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -44,14 +44,12 @@
44
44
 
45
45
  @extends('layouts.master_request')
46
46
 
47
- @section('title', 'Laravel tutorial(Biginner)')
47
+ @section('title', 'Laravel tutorial(Biginner)')
48
-
49
-
48
+
49
+
50
50
 
51
51
  @section('content')
52
52
 
53
-
54
-
55
53
  @if (count($errors) > 0)
56
54
 
57
55
  <ul>
@@ -154,9 +152,7 @@
154
152
 
155
153
  use App\Http\Requests\ItemRequest;
156
154
 
157
- class ItemController extends Controller
155
+ class ItemController extends Controller{
158
-
159
- {
160
156
 
161
157
  public function index()
162
158
 
@@ -198,13 +194,13 @@
198
194
 
199
195
    return redirect()->action('ItemController@index');
200
196
 
201
- }
197
+   }
202
198
 
203
199
    // GET
204
200
 
205
201
    return view('item.create');
206
202
 
207
- }
203
+   }
208
204
 
209
205
  }
210
206
 

3

表記内容

2018/07/19 00:54

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
File without changes

2

表記内容

2018/07/19 00:52

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -116,19 +116,19 @@
116
116
 
117
117
  <tbody>
118
118
 
119
- @foreach($ehime as $item)
119
+   @foreach($ehime as $item)
120
-
120
+
121
- <tr>
121
+   <tr>
122
-
122
+
123
-   <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
123
+     <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
124
-
124
+
125
- </tr>
125
+   </tr>
126
-
126
+
127
- @endforeach
127
+   @endforeach
128
128
 
129
129
  </tbody>
130
130
 
131
- </table>
131
+ </table>
132
132
 
133
133
  <!-- page control -->
134
134
 

1

表記内容

2018/07/19 00:46

投稿

Nitta
Nitta

スコア96

test CHANGED
File without changes
test CHANGED
@@ -76,19 +76,19 @@
76
76
 
77
77
  <label for="jan">Jan_Code:</label>
78
78
 
79
- <input type="text" class="form-control" name="jan" value="{{old('jan')}}">
79
+   <input type="text" class="form-control" name="jan" value="{{old('jan')}}">
80
80
 
81
81
  <br>
82
82
 
83
83
  <label for="name">Item_name</label>
84
84
 
85
- <input type="text" class="form-control" name="name" value="{{old('name')}}">
85
+ <input type="text" class="form-control" name="name" value="{{old('name')}}">
86
86
 
87
87
  <br>
88
88
 
89
89
  <label for="photo">Image_File(Multiple possible)</label>
90
90
 
91
- <input type="file" class="form-control" name="files[][photo]" multiple>
91
+ <input type="file" class="form-control" name="files[][photo]" multiple>
92
92
 
93
93
  <br>
94
94
 
@@ -120,7 +120,7 @@
120
120
 
121
121
  <tr>
122
122
 
123
- <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
123
+   <td>{{$item->item_id}}</td><td>{{$item->path}}</td>
124
124
 
125
125
  </tr>
126
126
 
@@ -158,15 +158,13 @@
158
158
 
159
159
  {
160
160
 
161
-
162
-
163
161
  public function index()
164
162
 
165
163
  {
166
164
 
167
- $items = ItemPhoto::all();
165
+   $items = ItemPhoto::all();
168
-
166
+
169
- return view('item.create')->with('ehime',$items);
167
+   return view('item.create')->with('ehime',$items);
170
168
 
171
169
  }
172
170
 
@@ -174,37 +172,37 @@
174
172
 
175
173
  {
176
174
 
177
- // POST
175
+   // POST
178
-
176
+
179
- if ($request->isMethod('POST')) {
177
+   if ($request->isMethod('POST')) {
180
-
178
+
181
- // 商品情報の保存
179
+   // 商品情報の保存
182
-
180
+
183
- $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
181
+   $item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
184
-
182
+
185
- // 商品画像の保存
183
+   // 商品画像の保存
186
-
184
+
187
- foreach ($request->file('files') as $index=> $e) {
185
+   foreach ($request->file('files') as $index=> $e) {
188
-
186
+
189
- $ext = $e['photo']->guessExtension();
187
+     $ext = $e['photo']->guessExtension();
190
-
188
+
191
- $filename = "{$request->jan}_{$index}.{$ext}";
189
+     $filename = "{$request->jan}_{$index}.{$ext}";
192
-
190
+
193
- $path = $e['photo']->storeAs('photos', $filename);
191
+     $path = $e['photo']->storeAs('photos', $filename);
194
-
192
+
195
- // photosメソッドにより、商品に紐付けられた画像を保存する
193
+    // photosメソッドにより、商品に紐付けられた画像を保存する
196
-
194
+
197
- $item->photos()->create(['path'=> $path]);
195
+    $item->photos()->create(['path'=> $path]);
198
-
196
+
199
- }
197
+   }
200
-
198
+
201
- return redirect()->action('ItemController@index');
199
+   return redirect()->action('ItemController@index');
202
-
200
+
203
- }
201
+ }
204
-
202
+
205
- // GET
203
+   // GET
206
-
204
+
207
- return view('item.create');
205
+   return view('item.create');
208
206
 
209
207
  }
210
208
 
@@ -222,15 +220,13 @@
222
220
 
223
221
  use Illuminate\Foundation\Http\FormRequest;
224
222
 
225
- class ItemRequest extends FormRequest
223
+ class ItemRequest extends FormRequest{
226
-
227
- {
228
224
 
229
225
  public function authorize()
230
226
 
231
227
  {
232
228
 
233
- return true;
229
+ return true;
234
230
 
235
231
  }
236
232
 
@@ -238,17 +234,17 @@
238
234
 
239
235
  {
240
236
 
241
- if($this->isMethod('get')) return[];
237
+   if($this->isMethod('get')) return[];
242
-
238
+
243
- return [
239
+   return [
244
-
240
+
245
- 'jan'=>'required',
241
+        'jan'=>'required',
246
-
242
+
247
- 'name'=>'required',
243
+        'name'=>'required',
248
-
244
+
249
- 'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
245
+        'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
250
-
246
+
251
- ];
247
+   ];
252
248
 
253
249
  }
254
250
 
@@ -256,16 +252,16 @@
256
252
 
257
253
  {
258
254
 
259
- return [
255
+   return [
260
-
256
+
261
- "required" => "Required items",
257
+        "required" => "Required items",
262
-
258
+
263
- "image" => "Specified files is not image files!!",
259
+        "image" => "Specified files is not image files!!",
264
-
260
+
265
- "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
261
+        "mines" => "Extension of specified files is not PNG or JPG or GIF!!",
266
-
262
+
267
- ];
263
+   ];
268
-
264
+
269
- }
265
+ }
270
-
266
+
271
- ```
267
+ ```