help me? I want to input multiple value and store in database with different row. with some other values inset in anther 2 different tables at same time. my controller not storing multiple values it just saving one values in "bill_products" and "item_lists" table. help me
example :
In input form, to "table name"( Purchases )
| product quantity price manufacturer |
| a 1 12$ xyz |
| b 2 1$ x |
| c 10 10$ y |
also insert selected fled 'product' 'quantity' 'price' this value to "table name"( bill_products)
| product quantity price |
| a 1 12$ |
| b 2 1$ |
| c 10 10$ |
also insert selected fled 'product' 'quantity' this value to "table name"( item_lists)
| product quantity |
| a 1 |
| b 2 |
| c 10 |
This is my view (purchase\purchase-entry.blade.php)
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">PURCHASE FORM</div>
<div class="card-body">
@if (Session::has('success'))
<div class="alert alert-success">{!! Session::get('success') !!}</div>
@endif
@if (Session::has('failure'))
<div class="alert alert-danger">{!! Session::get('failure') !!}</div>
@endif
<form method="POST" action="" enctype="multipart/form-data">
@csrf
<div class="form-row">
<div class="col-md-4 mb-3">
<label >product NAME</label>
<input type="text" name="product[]" placeholder="product" value="" required >
</div>
<div class="col-md-4 mb-3">
<label >quantity</label>
<input type="text" name="quantity[]" placeholder="quantity" value="" required >
</div>
<div class="col-md-4 mb-3">
<label >price</label>
<input type="text" name="price[]" placeholder=price" value="" required >
</div>
<div class="col-md-4 mb-3">
<label >manufacturer</label>
<input type="text" name="manufacturer[]" placeholder="manufacturer" value="" required >
</div>
</div>
</div>
<button class="btn btn-primary float-right" type="submit">SAVE</button>
</form>
this is route part
Route::post('purchasesave', 'PurchaseController@purchasesave')->name('purchasesave');
This is my controller (PurchaseController.php) and I have 3 model (Purchase , Bill_product and Item_list )
public function purchasesave(Request $request)
{
//insert your validation here
foreach($request->product as $k => $p){
Pruchases::create([
'product' => $request['product'][$k],
'quantity' => $request['quantity'][$k],
'price' => $request['price'][$k],
'manufacturer' => $request['manufacturer'][$k],
]);
BillProduct::create([
'product' => $request['product'][$k],
'quantity' => $request['quantity'][$k],
'price' => $request['price'][$k],
]);
ItemList::create([
'product' => $request['product'][$k],
'quantity' => $request['quantity'][$k],
]);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire