質問編集履歴
2
コントローラのコードは関係ないので削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,48 +37,4 @@
|
|
37
37
|
$('[name="long"]').val(location.lng());
|
38
38
|
});
|
39
39
|
}
|
40
|
-
```
|
41
|
-
コントローラ側のコード
|
42
|
-
```
|
43
|
-
public function create()
|
44
|
-
{
|
45
|
-
|
46
|
-
$data = [];
|
47
|
-
$user = \Auth::user();
|
48
|
-
$microposts =$user->microposts();
|
49
|
-
$data = ['user' => $user, 'microposts' => $microposts];
|
50
|
-
$data += $this->counts($user);
|
51
|
-
|
52
|
-
return view('microposts.create',$data);
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
public function store(Request $request)
|
58
|
-
{
|
59
|
-
$validator = Validator::make($request->all(),[
|
60
|
-
'photo' => 'required|image|max:5000',
|
61
|
-
'search_tag' => 'nullable',
|
62
|
-
'lat' => 'required',
|
63
|
-
'long' => 'required',
|
64
|
-
]);
|
65
|
-
|
66
|
-
if ($validator->fails()){
|
67
|
-
return back()->withErrors($validator)->withInput();
|
68
|
-
}
|
69
|
-
|
70
|
-
$micropost = $request->user()->microposts()->create([
|
71
|
-
'image_path' => $request->file('photo'),
|
72
|
-
'search_tag' => $request->search_tag,
|
73
|
-
'map_lat' => $request->lat,
|
74
|
-
'map_long' => $request->long,
|
75
|
-
]);
|
76
|
-
|
77
|
-
$path = Storage::disk('s3')->putFile('images', $request->file('photo'), 'public'); // s3/images/にアップ
|
78
|
-
$url = Storage::disk('s3')->url($path);
|
79
|
-
$micropost->image_path = $url;
|
80
|
-
$micropost->save();
|
81
|
-
return redirect()->route('microposts.show', ['id' => \Auth::id(), 'micropost' =>$micropost ])->with('success','ファイルはアップロードされました。');
|
82
|
-
|
83
|
-
}
|
84
40
|
```
|
1
コントローラ側のコードを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,4 +37,48 @@
|
|
37
37
|
$('[name="long"]').val(location.lng());
|
38
38
|
});
|
39
39
|
}
|
40
|
+
```
|
41
|
+
コントローラ側のコード
|
42
|
+
```
|
43
|
+
public function create()
|
44
|
+
{
|
45
|
+
|
46
|
+
$data = [];
|
47
|
+
$user = \Auth::user();
|
48
|
+
$microposts =$user->microposts();
|
49
|
+
$data = ['user' => $user, 'microposts' => $microposts];
|
50
|
+
$data += $this->counts($user);
|
51
|
+
|
52
|
+
return view('microposts.create',$data);
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
public function store(Request $request)
|
58
|
+
{
|
59
|
+
$validator = Validator::make($request->all(),[
|
60
|
+
'photo' => 'required|image|max:5000',
|
61
|
+
'search_tag' => 'nullable',
|
62
|
+
'lat' => 'required',
|
63
|
+
'long' => 'required',
|
64
|
+
]);
|
65
|
+
|
66
|
+
if ($validator->fails()){
|
67
|
+
return back()->withErrors($validator)->withInput();
|
68
|
+
}
|
69
|
+
|
70
|
+
$micropost = $request->user()->microposts()->create([
|
71
|
+
'image_path' => $request->file('photo'),
|
72
|
+
'search_tag' => $request->search_tag,
|
73
|
+
'map_lat' => $request->lat,
|
74
|
+
'map_long' => $request->long,
|
75
|
+
]);
|
76
|
+
|
77
|
+
$path = Storage::disk('s3')->putFile('images', $request->file('photo'), 'public'); // s3/images/にアップ
|
78
|
+
$url = Storage::disk('s3')->url($path);
|
79
|
+
$micropost->image_path = $url;
|
80
|
+
$micropost->save();
|
81
|
+
return redirect()->route('microposts.show', ['id' => \Auth::id(), 'micropost' =>$micropost ])->with('success','ファイルはアップロードされました。');
|
82
|
+
|
83
|
+
}
|
40
84
|
```
|