質問編集履歴

2

tuuii

2020/09/01 07:59

投稿

msd0624
msd0624

スコア15

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  ```
14
14
 
15
+ Failed to load resource: the server responded with a status of 404 (Not Found)
16
+
15
17
  GET http://localhost:3000/records/2766665e-0726-481f-8849-68281f0d2f9d 404 (Not Found)
16
18
 
17
19
  ```

1

バックエンドの追記

2020/09/01 07:59

投稿

msd0624
msd0624

スコア15

test CHANGED
File without changes
test CHANGED
@@ -26,9 +26,11 @@
26
26
 
27
27
  一つ目のコードでURLからIDでfetchメソッドでaction(getOPG)を叩く→二つ目のコードでaxios(get)で取得→mutationで状態を代入する。
28
28
 
29
+
30
+
31
+ ```
32
+
29
- ```nuxt.js
33
+ //nuxt.js
30
-
31
-
32
34
 
33
35
  <template>
34
36
 
@@ -84,7 +86,9 @@
84
86
 
85
87
 
86
88
 
89
+ ```
90
+
87
- ```nuxt(store/index.js)
91
+ //nuxt(store/index.js)
88
92
 
89
93
 
90
94
 
@@ -98,9 +102,155 @@
98
102
 
99
103
  commit("setOGP", data);
100
104
 
101
- }
105
+ }
106
+
102
-
107
+ ```
108
+
109
+
110
+
111
+ ```
112
+
113
+ //nuxt.config.js
114
+
115
+ axios: {
116
+
117
+ // See https://github.com/nuxt-community/axios-module#options
118
+
119
+ baseURL: "http://localhost:8000/",
120
+
121
+ // proxy: true
122
+
123
+ },
124
+
125
+ proxy: {
126
+
127
+ "/api": "/"
128
+
129
+ },
130
+
131
+ ```
132
+
133
+
134
+
135
+ ```
136
+
137
+ //Laravel(api.php)
138
+
139
+
140
+
141
+ <?php
142
+
143
+
144
+
145
+ use Illuminate\Http\Request;
146
+
147
+ // use Illuminate\Routing\Route;
148
+
149
+
150
+
151
+
152
+
153
+ Route::middleware('auth:api')->get('/user', function (Request $request) {
154
+
155
+ return $request->user();
156
+
103
- };
157
+ });
158
+
159
+ Route::post('/records','recordController@store');
160
+
161
+ Route::get('/records/{id}','recordController@show');
162
+
163
+ ```
164
+
165
+
166
+
167
+ ```
168
+
169
+ <?php
170
+
171
+
172
+
173
+ namespace App\Http\Controllers;
174
+
175
+
176
+
177
+ use App\Models\Record;
178
+
179
+ use DB;
180
+
181
+ use Exception;
182
+
183
+ use Illuminate\Http\Request;
184
+
185
+ use Str;
186
+
187
+ use Storage;
188
+
189
+
190
+
191
+ class recordController extends Controller
192
+
193
+ {
194
+
195
+ /**
196
+
197
+ * @param $id
198
+
199
+ * @return \Illuminate\Http\JsonResponse
200
+
201
+ */
202
+
203
+ //
204
+
205
+ public function show($id)
206
+
207
+ {
208
+
209
+ /** @var Record $record */
210
+
211
+ $record = Record::find($id);
212
+
213
+ // dd($record);
214
+
215
+ return response()->json([
216
+
217
+ 'message' => $record->message,
218
+
219
+ 'area' => $record->area,
220
+
221
+ 'reward' => $record->reward,
222
+
223
+ 'way' => $record->way,
224
+
225
+ 'time' => $record->time,
226
+
227
+ 'count' => $record->count,
228
+
229
+ 'url' => config('app.image_url') . '/' . $record->file_path
230
+
231
+ ]);
232
+
233
+ }
234
+
235
+ /**
236
+
237
+ * @param Request $request
238
+
239
+ * @return \Illuminate\Http\JsonResponse
240
+
241
+ * @throws \Throwable
242
+
243
+ */
244
+
245
+ public function store(Request $request)
246
+
247
+ {
248
+
249
+ //省略
250
+
251
+ }
252
+
253
+ }
104
254
 
105
255
  ```
106
256