teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

Controller部分の追記

2019/07/05 12:06

投稿

HirakuMorishima
HirakuMorishima

スコア29

title CHANGED
File without changes
body CHANGED
@@ -92,6 +92,19 @@
92
92
  <?php $subtotal += $val->bill_unit_price; ?>
93
93
  @endforeach
94
94
  ```
95
+
96
+ また、Controllerを以下のように変更しました。
97
+ ```php
98
+ $bills = Bill::where('invoice_id', '=', $request->bill_invoice_id)->get();
99
+ foreach($request->input("bills") as $id => $bill){
100
+ $bill->billing_item = $request->billing_item;
101
+ $bill->unit = $request->unit;
102
+ $bill->quantity = $request->quantity;
103
+ $bill->bill_unit_price = $request->bill_unit_price;
104
+ $bill->save();
105
+ }
106
+ ```
107
+
95
108
  しかし、ソースコードを確認するとarray[]の中が空欄となっていました。
96
109
  ![イメージ説明](7a8aefbd261f491dd935815b900877ac.png)
97
110
 

1

inputタグのname属性に[]を付け、配列型でControllerに受け渡した。

2019/07/05 12:06

投稿

HirakuMorishima
HirakuMorishima

スコア29

title CHANGED
File without changes
body CHANGED
@@ -65,4 +65,34 @@
65
65
  :
66
66
  :
67
67
  {{Form::close()}}
68
- ```
68
+ ```
69
+
70
+ ・・・追記
71
+ [manual](https://php.net/manual/ja/faq.html.php#faq.html.arrays)には、
72
+ name属性(例えばbilling_item)に対して[]を付ければ、
73
+ indexが数値として入るとのことでしたので、以下のようにbladeを変更しました。
74
+
75
+ ```php
76
+ @foreach($billList as $val)
77
+ <tr>
78
+ <!--品番・品名-->
79
+ <td>{{Form::text('billing_item[]', $val->billing_item,['class' => 'validate', 'id' => 'billing_item'])}}</td>
80
+ <!--数量-->
81
+ <td>{{Form::text('quantity[]', $val->quantity,['class' => 'validate', 'id' => 'quantity'])}}</td>
82
+ <!--単位-->
83
+ <td>{{Form::text('unit[]', $val->unit,['class' => 'validate', 'id' => 'unit'])}}</td>
84
+ <!--単価-->
85
+ <td>{{Form::text('bill_unit_price[]', ceil($val->bill_unit_price),['class' => 'validate', 'id' => 'bill_unit_price'])}}</td>
86
+ <!--金額-->
87
+ <td>{{$val->quantity * $val->bill_unit_price}}</td>
88
+ <td><a href="#" data-id="{{$val->id}}" class="waves-effect waves-light btn del">削除</a>
89
+ </td>
90
+ {{Form::hidden('bill_invoice_id', $val->invoice_id)}}
91
+ </tr>
92
+ <?php $subtotal += $val->bill_unit_price; ?>
93
+ @endforeach
94
+ ```
95
+ しかし、ソースコードを確認するとarray[]の中が空欄となっていました。
96
+ ![イメージ説明](7a8aefbd261f491dd935815b900877ac.png)
97
+
98
+ https://php.net/manual/ja/faq.html.php#faq.html.arraysについても参照したのですが、問題が分かりませんでした…。再度、助言いただけましたら幸いです。