質問編集履歴

2

コード変更 editとupdate部分

2018/12/29 05:08

投稿

Ryosukevvvv
Ryosukevvvv

スコア19

test CHANGED
File without changes
test CHANGED
@@ -2,50 +2,60 @@
2
2
 
3
3
  ```RecipesController
4
4
 
5
- // getでrecipes/id/editにアクセスされた場合の「更新画面表示処理」
6
-
7
- public function edit($id)
5
+ public function edit($id)
8
6
 
9
7
  {
10
8
 
11
9
  $recipe = Recipe::find($id);
12
10
 
11
+ $ingredient = Recipe::find($id)->ingredient;
12
+
13
+ $how_to = Recipe::find($id)->how_to;
14
+
15
+
16
+
17
+ return view('recipes.edit',[
18
+
19
+ 'recipe' => $recipe,
20
+
21
+ 'ingredients' => $ingredient,
22
+
23
+ 'how_tos' => $how_to,
24
+
25
+ ]);
26
+
27
+ }
28
+
29
+ ```
30
+
31
+ ```RecipesController
32
+
33
+ // putまたはpatchでrecipes/idにアクセスされた場合の「更新処理」
34
+
35
+ public function update(Request $request, $id)
36
+
37
+ {
38
+
39
+ $recipe = Recipe::find($id);
40
+
41
+ $ingredient = Recipe::find($id)->ingredient;
42
+
43
+ $how_to = Recipe::find($id)->how_to;
44
+
45
+ $recipe->name = $recipe->name;
46
+
47
+ $recipe->content = $recipe->content;
48
+
49
+ $ingredient->ingredient = $ingredient->ingredient;
50
+
51
+ $ingredient->quantity = $ingredient->quantity;
52
+
53
+ $how_to->how_to_make = $how_to->how_to_make;
54
+
55
+ $recipe->save();
56
+
13
57
 
14
58
 
15
- return view('recipes.edit',[
16
-
17
- 'recipe' => $recipe
18
-
19
- ]);
20
-
21
- }
22
-
23
- ```
24
-
25
- ```RecipesController
26
-
27
- // putまたはpatchでrecipes/idにアクセスされた場合の「更新処理」
28
-
29
- public function update(Request $request, $id)
30
-
31
- {
32
-
33
- $recipe = Recipe::find($id);
34
-
35
- $recipe->name = $recipe->name;
36
-
37
- $recipe->content = $recipe->content;
38
-
39
- $recipe->ingredient = $recipe->ingredient;
40
-
41
- $recipe->quantity = $recipe->quantity;
42
-
43
- $recipe->how_to_make = $recipe->how_to_make;
44
-
45
- $recipe->save();
46
-
47
-
48
-
49
59
  return back();
50
60
 
51
61
  }

1

エラー文

2018/12/29 05:08

投稿

Ryosukevvvv
Ryosukevvvv

スコア19

test CHANGED
File without changes
test CHANGED
@@ -326,4 +326,12 @@
326
326
 
327
327
  また、更新ボタンを押してもエラーが発生し、うまく更新されません。
328
328
 
329
+ 更新の際のエラーはこちらです。
330
+
331
+ ```
332
+
333
+ SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ingredient' in 'field list' (SQL: update `recipes` set `updated_at` = 2018-12-29 13:42:36, `ingredient` = [], `quantity` = , `how_to_make` = where `id` = 27)
334
+
335
+ ```
336
+
329
337
  どこがおかしいのでしょうか?