У меня есть две таблицы, одна называется заголовком, а другая - деталями элемента. Поля, такие как дата, имя поставщика, номер счета будут идти в таблицу заголовков, а имя товара, кол-во и цена за единицу товара - в таблицу сведений о товаре.
Теперь проблема в таблице товара, у нас есть форма с 5 полями ввода, пользователь введет детали элемента в форму и отправит, но только один элемент будет сохранен. Я знаю, что нам нужно работать с массивом, но я не знаю, как написать код для этого ... Кто-нибудь, пожалуйста, дайте мне?
<tr>
<td class="text-center">1</td>
<td ><input type="text" class="form-control text-uppercase" name = "item_name[]" id="row1"></td>
<td ><input class="form-control text-center" type="text" onkeypress="return isNumberKey(event)" name="qty" id="qty1" onkeyup="calc1()" value=""></td>
<td ><input class="form-control text-right" type="text" onkeypress="return isNumberKey(event)" name="unit_price" id="price1" onkeyup="calc1()" value=""></td>
<td > <input class="form-control text-right" type="text" name="amount" id="amount1" value="" disabled></td>
</tr>
<tr>
<td class="text-center">2</td>
<td ><input type="text" class="form-control text-uppercase" name = "item_name[]" id="row2"></td>
<td ><input class="form-control text-center" type="text" onkeypress="return isNumberKey(event)" name="qty" id="qty2" onkeyup="calc2()" value=""></td>
<td ><input class="form-control text-right" type="text" onkeypress="return isNumberKey(event)" name="unit_price" id="price2" onkeyup="calc2()" value=""></td>
<td > <input class="form-control text-right" type="text" name="amount" id="amount2" value="" disabled></td>
</tr>
<tr>
<td class="text-center">3</td>
<td ><input type="text" class="form-control text-uppercase" name = "item_name[]" id="row3"></td>
<td ><input class="form-control text-center" type="text" onkeypress="return isNumberKey(event)" name="qty" id="qty3" onkeyup="calc3()" value=""></td>
<td ><input class="form-control text-right" type="text" onkeypress="return isNumberKey(event)" name="unit_price" id="price3" onkeyup="calc3()" value=""></td>
<td > <input class="form-control text-right" type="text" name="amount" id="amount3" value="" disabled></td>
</tr>
<tr>
<td class="text-center"></td>
<td class="text-right" colspan="3"><label>Total</label></td>
<td><input type="text" class="form-control text-right" onkeyup="bill_total()" name = "total" id="total" disabled></td>
</tr>
enter code here
магазин общедоступных функций (запрос $ запрос, учетная запись $ account, Item $ item) {
if($request->attach->getClientOriginalName())
{
$ext = $request->attach->getClientOriginalExtension();
$file = date('YmdHis').rand(1,99999).'.'.$ext;
$request->attach->storeAs('public/categories',$file);
}
else
{
$file='';
}
$account->attach = $file;
$account->supp_name = $request->supp_name;
$account->emp_name = $request->emp_name;
$account->item_type = $request->item_type;
$account->bill_date = $request->bill_date;
$account->bill_amt = $request->bill_amt;
$account->bill_no = $request->bill_no;
$account->pay_mode = $request->pay_mode;
$account->purpose = $request->purpose;
$account->item_type = $request->item_type;
$account->save();
$item->item_name = $request->item_name;
$item->qty = $request->qty;
$item->unit_price = $request->unit_price;
$item->save();
return redirect('admin/accounts');
}