I have a problem trying to send values in the form of an array from the input, what is the solution? And each array of data is in a separate line in the data base and has an id as if I entered the data more than once
I searched a lot, but I did not find a solution to this problem. Can someone help me? Thank you
//blade
<td>
<input type="text" class="qty form-control" name="p_unit[]">
@error('p_unit.*')
<div class="alert alert-danger" role="alert">
</div>
@enderror
</td>
<td>
<input type="text" class="qty form-control" name="p_lastPrice[]">
@error('p_lastPrice.*')
<div class="alert alert-danger" role="alert">
</div>
@enderror
</td>
<td>
<input type="text" class="qty form-control" name="p_averagecost[]">
@error('p_averagecost.*')
<div class="alert alert-danger" role="alert">
</div>
@enderror
</td>
<td><input type="text" class="form-control" name="p_priceA[]"></td>
<td>
<input type="text" class="form-control weight" name="p_priceB[]">
@error('p_priceB.*')
<div class="alert alert-danger" role="alert">
</div>
@enderror
</td>
<td>
<input type="text" class="form-control unit_cost" name="p_priceC[]">
@error('p_priceC.*')
<div class="alert alert-danger" role="alert">
</div>
@enderror
</td>
I have an activated button that repeats the same fields to fill them in again, and after that I want to send the data in an array to the database
// controller
$products = $request->p_code;
for ($i=0; $i<count($products); $i++)
{
$items = productUnitPrice::create([
'p_code' => $request->p_code,
'p_packing' => $request->p_packing[$i],
'p_conversionfactor' => $request->p_conversionfactor[$i],
'p_unit' => $request->p_unit[$i],
'p_lastPrice' => $request->p_lastPrice[$i],
'p_averagecost' => $request->p_averagecost[$i],
'p_priceA' => $request->p_priceA[$i],
'p_priceB' => $request->p_priceB[$i],
'p_priceC' => $request->p_priceC[$i],
]);
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/504s3mQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire