質問編集履歴
2
コントローラのコードは関係ないので削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,91 +77,3 @@
|
|
77
77
|
}
|
78
78
|
|
79
79
|
```
|
80
|
-
|
81
|
-
コントローラ側のコード
|
82
|
-
|
83
|
-
```
|
84
|
-
|
85
|
-
public function create()
|
86
|
-
|
87
|
-
{
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
$data = [];
|
92
|
-
|
93
|
-
$user = \Auth::user();
|
94
|
-
|
95
|
-
$microposts =$user->microposts();
|
96
|
-
|
97
|
-
$data = ['user' => $user, 'microposts' => $microposts];
|
98
|
-
|
99
|
-
$data += $this->counts($user);
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
return view('microposts.create',$data);
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
public function store(Request $request)
|
114
|
-
|
115
|
-
{
|
116
|
-
|
117
|
-
$validator = Validator::make($request->all(),[
|
118
|
-
|
119
|
-
'photo' => 'required|image|max:5000',
|
120
|
-
|
121
|
-
'search_tag' => 'nullable',
|
122
|
-
|
123
|
-
'lat' => 'required',
|
124
|
-
|
125
|
-
'long' => 'required',
|
126
|
-
|
127
|
-
]);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
if ($validator->fails()){
|
132
|
-
|
133
|
-
return back()->withErrors($validator)->withInput();
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
$micropost = $request->user()->microposts()->create([
|
140
|
-
|
141
|
-
'image_path' => $request->file('photo'),
|
142
|
-
|
143
|
-
'search_tag' => $request->search_tag,
|
144
|
-
|
145
|
-
'map_lat' => $request->lat,
|
146
|
-
|
147
|
-
'map_long' => $request->long,
|
148
|
-
|
149
|
-
]);
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
$path = Storage::disk('s3')->putFile('images', $request->file('photo'), 'public'); // s3/images/にアップ
|
154
|
-
|
155
|
-
$url = Storage::disk('s3')->url($path);
|
156
|
-
|
157
|
-
$micropost->image_path = $url;
|
158
|
-
|
159
|
-
$micropost->save();
|
160
|
-
|
161
|
-
return redirect()->route('microposts.show', ['id' => \Auth::id(), 'micropost' =>$micropost ])->with('success','ファイルはアップロードされました。');
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
```
|
1
コントローラ側のコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,3 +77,91 @@
|
|
77
77
|
}
|
78
78
|
|
79
79
|
```
|
80
|
+
|
81
|
+
コントローラ側のコード
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
public function create()
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
$data = [];
|
92
|
+
|
93
|
+
$user = \Auth::user();
|
94
|
+
|
95
|
+
$microposts =$user->microposts();
|
96
|
+
|
97
|
+
$data = ['user' => $user, 'microposts' => $microposts];
|
98
|
+
|
99
|
+
$data += $this->counts($user);
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
return view('microposts.create',$data);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public function store(Request $request)
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
$validator = Validator::make($request->all(),[
|
118
|
+
|
119
|
+
'photo' => 'required|image|max:5000',
|
120
|
+
|
121
|
+
'search_tag' => 'nullable',
|
122
|
+
|
123
|
+
'lat' => 'required',
|
124
|
+
|
125
|
+
'long' => 'required',
|
126
|
+
|
127
|
+
]);
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if ($validator->fails()){
|
132
|
+
|
133
|
+
return back()->withErrors($validator)->withInput();
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
$micropost = $request->user()->microposts()->create([
|
140
|
+
|
141
|
+
'image_path' => $request->file('photo'),
|
142
|
+
|
143
|
+
'search_tag' => $request->search_tag,
|
144
|
+
|
145
|
+
'map_lat' => $request->lat,
|
146
|
+
|
147
|
+
'map_long' => $request->long,
|
148
|
+
|
149
|
+
]);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
$path = Storage::disk('s3')->putFile('images', $request->file('photo'), 'public'); // s3/images/にアップ
|
154
|
+
|
155
|
+
$url = Storage::disk('s3')->url($path);
|
156
|
+
|
157
|
+
$micropost->image_path = $url;
|
158
|
+
|
159
|
+
$micropost->save();
|
160
|
+
|
161
|
+
return redirect()->route('microposts.show', ['id' => \Auth::id(), 'micropost' =>$micropost ])->with('success','ファイルはアップロードされました。');
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
```
|