質問編集履歴
10
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,18 +34,18 @@
|
|
34
34
|
@section('content')
|
35
35
|
@if (count($errors) > 0)
|
36
36
|
<ul>
|
37
|
-
|
37
|
+
@foreach($errors->all() as $error)
|
38
|
-
|
38
|
+
<li>{{ $error }}</li>
|
39
|
-
|
39
|
+
@endforeach
|
40
40
|
</ul>
|
41
41
|
@endif
|
42
42
|
<!-- フォーム -->
|
43
43
|
<h3>Form_Sample(Enter_Screen)</h3>
|
44
44
|
<p>Please enter items</p>
|
45
45
|
<form action="{{ url('create') }}" method="POST" enctype="multipart/form-data">
|
46
|
-
|
46
|
+
<label for="jan">Jan_Code:</label>
|
47
|
-
|
47
|
+
<input type="text" class="form-control" name="jan" value="{{old('jan')}}">
|
48
|
-
|
48
|
+
<br>
|
49
49
|
<label for="name">Item_name</label>
|
50
50
|
<input type="text" class="form-control" name="name" value="{{old('name')}}">
|
51
51
|
<br>
|
@@ -57,19 +57,19 @@
|
|
57
57
|
<button class="btn btn-success"> Upload </button>
|
58
58
|
</form>
|
59
59
|
<table class="table table-striped table-hover">
|
60
|
-
|
60
|
+
<thead>
|
61
|
-
|
61
|
+
<tr>
|
62
|
-
|
62
|
+
<th>No</th>
|
63
|
-
|
63
|
+
<th>name</th>
|
64
|
-
|
64
|
+
</tr>
|
65
|
-
|
65
|
+
</thead>
|
66
|
-
|
66
|
+
<tbody>
|
67
67
|
@foreach($ehime as $item)
|
68
68
|
<tr>
|
69
|
-
|
69
|
+
<td>{{$item->item_id}}</td><td>{{$item->path}}</td>
|
70
70
|
</tr>
|
71
71
|
@endforeach
|
72
|
-
|
72
|
+
</tbody>
|
73
73
|
</table>
|
74
74
|
<!-- page control -->
|
75
75
|
{!! $ehime->render() !!}
|
@@ -87,27 +87,27 @@
|
|
87
87
|
|
88
88
|
public function index()
|
89
89
|
{
|
90
|
-
|
90
|
+
$items = ItemPhoto::all();
|
91
|
-
|
91
|
+
return view('item.create')->with('ehime',$items);
|
92
92
|
}
|
93
93
|
|
94
94
|
public function create(Request $request)
|
95
95
|
{
|
96
|
-
|
96
|
+
// POST
|
97
|
-
|
97
|
+
if($request->isMethod('POST')) {
|
98
|
-
|
98
|
+
// 商品情報の保存
|
99
|
-
|
99
|
+
$item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
|
100
|
-
|
100
|
+
// 商品画像の保存
|
101
|
-
|
101
|
+
foreach ($request->file('files') as $index=> $e) {
|
102
|
-
|
102
|
+
$ext = $e['photo']->guessExtension();
|
103
|
-
|
103
|
+
$filename = "{$request->jan}_{$index}.{$ext}";
|
104
|
-
|
104
|
+
$path = $e['photo']->storeAs('photos', $filename);
|
105
|
-
|
105
|
+
// photosメソッドにより、商品に紐付けられた画像を保存する
|
106
|
-
|
106
|
+
$item->photos()->create(['path'=> $path]);
|
107
|
-
|
107
|
+
}
|
108
|
-
|
108
|
+
return redirect()->action('ItemController@index');
|
109
109
|
}
|
110
|
-
|
110
|
+
// GET
|
111
111
|
return view('item.create');
|
112
112
|
}
|
113
113
|
|
@@ -127,21 +127,21 @@
|
|
127
127
|
|
128
128
|
public function rules()
|
129
129
|
{
|
130
|
-
|
130
|
+
if($this->isMethod('get')) return[];
|
131
|
-
|
131
|
+
return [
|
132
|
-
|
132
|
+
'jan'=>'required',
|
133
|
-
|
133
|
+
'name'=>'required',
|
134
|
-
|
134
|
+
'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
|
135
|
-
|
135
|
+
];
|
136
136
|
}
|
137
137
|
|
138
138
|
public function messages()
|
139
139
|
{
|
140
|
-
|
140
|
+
return [
|
141
|
-
|
141
|
+
"required" => "Required items",
|
142
|
-
|
142
|
+
"image" => "Specified files is not image files!!",
|
143
|
-
|
143
|
+
"mines" => "Extension of specified files is not PNG or JPG or GIF!!",
|
144
|
-
|
144
|
+
];
|
145
145
|
}
|
146
146
|
|
147
147
|
}
|
9
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,8 +10,16 @@
|
|
10
10
|
<エラー名>
|
11
11
|
Method Illuminate\Database\Eloquent\Collection::render does not exist
|
12
12
|
(Collectionクラスにrenderメソッドはない)
|
13
|
+
|
13
14
|
<やったこと>
|
14
15
|
$ehime->render()や$ehime->links()で試したがダメ
|
16
|
+
|
17
|
+
<参考サイト>
|
18
|
+
①Laravelのvalidationメソッドでバリデーションを実装する入門編(日本語エラーメッセージ付き)
|
19
|
+
https://www.ritolab.com/entry/40
|
20
|
+
②laravel5.5を使用して複数画像をアップロードする方法
|
21
|
+
https://qiita.com/netfish/items/ef01cdb5f58742563e87
|
22
|
+
|
15
23
|
<記入内容>
|
16
24
|
web.php
|
17
25
|
```
|
8
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -86,7 +86,7 @@
|
|
86
86
|
public function create(Request $request)
|
87
87
|
{
|
88
88
|
// POST
|
89
|
-
if
|
89
|
+
if($request->isMethod('POST')) {
|
90
90
|
// 商品情報の保存
|
91
91
|
$item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
|
92
92
|
// 商品画像の保存
|
@@ -96,13 +96,13 @@
|
|
96
96
|
$path = $e['photo']->storeAs('photos', $filename);
|
97
97
|
// photosメソッドにより、商品に紐付けられた画像を保存する
|
98
98
|
$item->photos()->create(['path'=> $path]);
|
99
|
-
|
99
|
+
}
|
100
100
|
return redirect()->action('ItemController@index');
|
101
101
|
}
|
102
102
|
// GET
|
103
103
|
return view('item.create');
|
104
104
|
}
|
105
|
-
|
105
|
+
|
106
106
|
}
|
107
107
|
```
|
108
108
|
バリデーション(ItemRequest.php)
|
7
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,11 +76,13 @@
|
|
76
76
|
use App\ItemPhoto;
|
77
77
|
use App\Http\Requests\ItemRequest;
|
78
78
|
class ItemController extends Controller{
|
79
|
+
|
79
80
|
public function index()
|
80
81
|
{
|
81
82
|
$items = ItemPhoto::all();
|
82
83
|
return view('item.create')->with('ehime',$items);
|
83
84
|
}
|
85
|
+
|
84
86
|
public function create(Request $request)
|
85
87
|
{
|
86
88
|
// POST
|
@@ -99,7 +101,8 @@
|
|
99
101
|
}
|
100
102
|
// GET
|
101
103
|
return view('item.create');
|
102
|
-
}
|
104
|
+
}
|
105
|
+
|
103
106
|
}
|
104
107
|
```
|
105
108
|
バリデーション(ItemRequest.php)
|
@@ -108,10 +111,12 @@
|
|
108
111
|
namespace App\Http\Requests;
|
109
112
|
use Illuminate\Foundation\Http\FormRequest;
|
110
113
|
class ItemRequest extends FormRequest{
|
114
|
+
|
111
115
|
public function authorize()
|
112
116
|
{
|
113
117
|
return true;
|
114
118
|
}
|
119
|
+
|
115
120
|
public function rules()
|
116
121
|
{
|
117
122
|
if($this->isMethod('get')) return[];
|
@@ -121,6 +126,7 @@
|
|
121
126
|
'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
|
122
127
|
];
|
123
128
|
}
|
129
|
+
|
124
130
|
public function messages()
|
125
131
|
{
|
126
132
|
return [
|
@@ -129,5 +135,6 @@
|
|
129
135
|
"mines" => "Extension of specified files is not PNG or JPG or GIF!!",
|
130
136
|
];
|
131
137
|
}
|
138
|
+
|
132
139
|
}
|
133
140
|
```
|
6
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -99,7 +99,7 @@
|
|
99
99
|
}
|
100
100
|
// GET
|
101
101
|
return view('item.create');
|
102
|
-
|
102
|
+
}
|
103
103
|
}
|
104
104
|
```
|
105
105
|
バリデーション(ItemRequest.php)
|
5
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,15 +76,15 @@
|
|
76
76
|
use App\ItemPhoto;
|
77
77
|
use App\Http\Requests\ItemRequest;
|
78
78
|
class ItemController extends Controller{
|
79
|
-
public function index()
|
79
|
+
public function index()
|
80
|
-
{
|
80
|
+
{
|
81
|
-
|
81
|
+
$items = ItemPhoto::all();
|
82
|
-
|
82
|
+
return view('item.create')->with('ehime',$items);
|
83
|
-
}
|
83
|
+
}
|
84
|
-
public function create(Request $request)
|
84
|
+
public function create(Request $request)
|
85
|
-
{
|
85
|
+
{
|
86
|
-
|
86
|
+
// POST
|
87
|
-
|
87
|
+
if ($request->isMethod('POST')) {
|
88
88
|
// 商品情報の保存
|
89
89
|
$item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
|
90
90
|
// 商品画像の保存
|
@@ -94,12 +94,12 @@
|
|
94
94
|
$path = $e['photo']->storeAs('photos', $filename);
|
95
95
|
// photosメソッドにより、商品に紐付けられた画像を保存する
|
96
96
|
$item->photos()->create(['path'=> $path]);
|
97
|
-
|
97
|
+
}
|
98
|
-
|
98
|
+
return redirect()->action('ItemController@index');
|
99
|
-
|
99
|
+
}
|
100
|
-
|
100
|
+
// GET
|
101
|
-
|
101
|
+
return view('item.create');
|
102
|
-
|
102
|
+
}
|
103
103
|
}
|
104
104
|
```
|
105
105
|
バリデーション(ItemRequest.php)
|
@@ -108,25 +108,26 @@
|
|
108
108
|
namespace App\Http\Requests;
|
109
109
|
use Illuminate\Foundation\Http\FormRequest;
|
110
110
|
class ItemRequest extends FormRequest{
|
111
|
-
public function authorize()
|
111
|
+
public function authorize()
|
112
|
-
{
|
112
|
+
{
|
113
113
|
return true;
|
114
|
-
}
|
114
|
+
}
|
115
|
-
public function rules()
|
115
|
+
public function rules()
|
116
|
-
{
|
116
|
+
{
|
117
|
-
|
117
|
+
if($this->isMethod('get')) return[];
|
118
|
-
|
118
|
+
return [
|
119
119
|
'jan'=>'required',
|
120
120
|
'name'=>'required',
|
121
121
|
'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
|
122
|
-
|
122
|
+
];
|
123
|
-
}
|
123
|
+
}
|
124
|
-
public function messages()
|
124
|
+
public function messages()
|
125
|
-
{
|
125
|
+
{
|
126
126
|
return [
|
127
127
|
"required" => "Required items",
|
128
128
|
"image" => "Specified files is not image files!!",
|
129
129
|
"mines" => "Extension of specified files is not PNG or JPG or GIF!!",
|
130
130
|
];
|
131
|
+
}
|
131
132
|
}
|
132
133
|
```
|
4
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,10 +21,9 @@
|
|
21
21
|
form(create.blade.php)
|
22
22
|
```
|
23
23
|
@extends('layouts.master_request')
|
24
|
-
@section('title', 'Laravel tutorial(Biginner)')
|
24
|
+
@section('title', 'Laravel tutorial(Biginner)')
|
25
|
-
|
25
|
+
|
26
26
|
@section('content')
|
27
|
-
|
28
27
|
@if (count($errors) > 0)
|
29
28
|
<ul>
|
30
29
|
@foreach($errors->all() as $error)
|
@@ -76,8 +75,7 @@
|
|
76
75
|
use App\Item;
|
77
76
|
use App\ItemPhoto;
|
78
77
|
use App\Http\Requests\ItemRequest;
|
79
|
-
class ItemController extends Controller
|
78
|
+
class ItemController extends Controller{
|
80
|
-
{
|
81
79
|
public function index()
|
82
80
|
{
|
83
81
|
$items = ItemPhoto::all();
|
@@ -98,10 +96,10 @@
|
|
98
96
|
$item->photos()->create(['path'=> $path]);
|
99
97
|
}
|
100
98
|
return redirect()->action('ItemController@index');
|
101
|
-
}
|
99
|
+
}
|
102
100
|
// GET
|
103
101
|
return view('item.create');
|
104
|
-
}
|
102
|
+
}
|
105
103
|
}
|
106
104
|
```
|
107
105
|
バリデーション(ItemRequest.php)
|
3
表記内容
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
2
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -57,13 +57,13 @@
|
|
57
57
|
</tr>
|
58
58
|
</thead>
|
59
59
|
<tbody>
|
60
|
-
|
60
|
+
@foreach($ehime as $item)
|
61
|
-
|
61
|
+
<tr>
|
62
|
-
|
62
|
+
<td>{{$item->item_id}}</td><td>{{$item->path}}</td>
|
63
|
-
|
63
|
+
</tr>
|
64
|
-
|
64
|
+
@endforeach
|
65
65
|
</tbody>
|
66
|
-
|
66
|
+
</table>
|
67
67
|
<!-- page control -->
|
68
68
|
{!! $ehime->render() !!}
|
69
69
|
@endsection
|
1
表記内容
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,13 +37,13 @@
|
|
37
37
|
<p>Please enter items</p>
|
38
38
|
<form action="{{ url('create') }}" method="POST" enctype="multipart/form-data">
|
39
39
|
<label for="jan">Jan_Code:</label>
|
40
|
-
|
40
|
+
<input type="text" class="form-control" name="jan" value="{{old('jan')}}">
|
41
41
|
<br>
|
42
42
|
<label for="name">Item_name</label>
|
43
|
-
|
43
|
+
<input type="text" class="form-control" name="name" value="{{old('name')}}">
|
44
44
|
<br>
|
45
45
|
<label for="photo">Image_File(Multiple possible)</label>
|
46
|
-
|
46
|
+
<input type="file" class="form-control" name="files[][photo]" multiple>
|
47
47
|
<br>
|
48
48
|
<hr>
|
49
49
|
{{ csrf_field() }}
|
@@ -59,7 +59,7 @@
|
|
59
59
|
<tbody>
|
60
60
|
@foreach($ehime as $item)
|
61
61
|
<tr>
|
62
|
-
|
62
|
+
<td>{{$item->item_id}}</td><td>{{$item->path}}</td>
|
63
63
|
</tr>
|
64
64
|
@endforeach
|
65
65
|
</tbody>
|
@@ -78,30 +78,29 @@
|
|
78
78
|
use App\Http\Requests\ItemRequest;
|
79
79
|
class ItemController extends Controller
|
80
80
|
{
|
81
|
-
|
82
81
|
public function index()
|
83
82
|
{
|
84
|
-
$items = ItemPhoto::all();
|
83
|
+
$items = ItemPhoto::all();
|
85
|
-
return view('item.create')->with('ehime',$items);
|
84
|
+
return view('item.create')->with('ehime',$items);
|
86
85
|
}
|
87
86
|
public function create(Request $request)
|
88
87
|
{
|
89
|
-
// POST
|
88
|
+
// POST
|
90
|
-
if ($request->isMethod('POST')) {
|
89
|
+
if ($request->isMethod('POST')) {
|
91
|
-
// 商品情報の保存
|
90
|
+
// 商品情報の保存
|
92
|
-
$item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
|
91
|
+
$item = Item::create(['jan'=> $request->jan, 'name'=> $request->name]);
|
93
|
-
// 商品画像の保存
|
92
|
+
// 商品画像の保存
|
94
|
-
foreach ($request->file('files') as $index=> $e) {
|
93
|
+
foreach ($request->file('files') as $index=> $e) {
|
95
|
-
$ext = $e['photo']->guessExtension();
|
94
|
+
$ext = $e['photo']->guessExtension();
|
96
|
-
$filename = "{$request->jan}_{$index}.{$ext}";
|
95
|
+
$filename = "{$request->jan}_{$index}.{$ext}";
|
97
|
-
$path = $e['photo']->storeAs('photos', $filename);
|
96
|
+
$path = $e['photo']->storeAs('photos', $filename);
|
98
|
-
// photosメソッドにより、商品に紐付けられた画像を保存する
|
97
|
+
// photosメソッドにより、商品に紐付けられた画像を保存する
|
99
|
-
$item->photos()->create(['path'=> $path]);
|
98
|
+
$item->photos()->create(['path'=> $path]);
|
99
|
+
}
|
100
|
+
return redirect()->action('ItemController@index');
|
100
101
|
}
|
101
|
-
return redirect()->action('ItemController@index');
|
102
|
-
}
|
103
|
-
// GET
|
102
|
+
// GET
|
104
|
-
return view('item.create');
|
103
|
+
return view('item.create');
|
105
104
|
}
|
106
105
|
}
|
107
106
|
```
|
@@ -110,27 +109,26 @@
|
|
110
109
|
<?php
|
111
110
|
namespace App\Http\Requests;
|
112
111
|
use Illuminate\Foundation\Http\FormRequest;
|
113
|
-
class ItemRequest extends FormRequest
|
112
|
+
class ItemRequest extends FormRequest{
|
114
|
-
{
|
115
113
|
public function authorize()
|
116
114
|
{
|
117
|
-
|
115
|
+
return true;
|
118
116
|
}
|
119
117
|
public function rules()
|
120
118
|
{
|
121
|
-
if($this->isMethod('get')) return[];
|
119
|
+
if($this->isMethod('get')) return[];
|
122
|
-
return [
|
120
|
+
return [
|
123
|
-
'jan'=>'required',
|
121
|
+
'jan'=>'required',
|
124
|
-
'name'=>'required',
|
122
|
+
'name'=>'required',
|
125
|
-
'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
|
123
|
+
'file.*.photo'=>'required|image|mimes:jpeg,png,jpg,gif',
|
126
|
-
];
|
124
|
+
];
|
127
125
|
}
|
128
126
|
public function messages()
|
129
127
|
{
|
130
|
-
return [
|
128
|
+
return [
|
131
|
-
"required" => "Required items",
|
129
|
+
"required" => "Required items",
|
132
|
-
"image" => "Specified files is not image files!!",
|
130
|
+
"image" => "Specified files is not image files!!",
|
133
|
-
"mines" => "Extension of specified files is not PNG or JPG or GIF!!",
|
131
|
+
"mines" => "Extension of specified files is not PNG or JPG or GIF!!",
|
134
|
-
];
|
132
|
+
];
|
135
133
|
}
|
136
134
|
```
|