回答編集履歴

2

タイトル修正

2018/07/08 08:06

投稿

hiroaki510
hiroaki510

スコア16

test CHANGED
@@ -1,4 +1,4 @@
1
- #自己解決出来ました
1
+ #回答を参考にし、解決出来ました
2
2
 
3
3
  ```
4
4
 

1

コード変更

2018/07/08 08:05

投稿

hiroaki510
hiroaki510

スコア16

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  <tr><th></th><td><button type="submit">設定</button></td></tr>
36
36
 
37
- //下記を追加
37
+ //下記を追加
38
38
 
39
39
  @if(empty($investmentPrincipal[0]))
40
40
 
@@ -53,3 +53,41 @@
53
53
  ```
54
54
 
55
55
  ただ、これより良いコードがあるとおもうので、余裕があれば違う記述方法を勉強していきます。
56
+
57
+
58
+
59
+ 7/5:追記
60
+
61
+ @if文でエラーメッセージを書くのはおかしいので、@foreach文でuser_idの値を送ることにしました。
62
+
63
+ ```
64
+
65
+ <form method="POST" action="/make/principal">
66
+
67
+ {{ csrf_field() }}
68
+
69
+ @if($errors->has('principal'))
70
+
71
+ <tr><th>ERROR</th><td>{{$errors->first('principal')}}</td></tr>
72
+
73
+ @endif
74
+
75
+
76
+
77
+ <tr><th>投資元本: </th><td><input type="text" name="principal" value="{{old('principal')}}"></td></tr>
78
+
79
+ <tr><th></th><td><button type="submit">設定</button></td></tr>
80
+
81
+ //下記を追加
82
+
83
+  //$investmentPrincipalはassetsテーブルのモデルクラスが代入されたもの
84
+
85
+ @foreach($investmentPrincipal as $principal)
86
+
87
+ <input type="hidden" name="user" value="{{$principal->user_id}}">
88
+
89
+ @endforeach
90
+
91
+ </form>
92
+
93
+ ```