laravel controller : update function for multiple dynamic rows

invoice_service TableInvoice Table

the edit function works well in EditInvoice blade and the specific rows are displayed with their value. Example : if I choose to edit invoice N17 , in EditInvoice blade 2 results will be appear (see table image).

for the next step , I need to update this 2 results value(invoice services). I try many ways in update function but didnt work.

  • store function : works well
public function store(Request $request) : 
...
.....
$designation = $request->designation;
$QTE = $request->QTE;
$PU = $request->PU;
$total = $request->total;

$c = count($request->designation);
for ( $i=0; $i< $c; ++$i) { //get all rows(dynamic add/remove)
$invoice_number = $request->invoice_number;
$invoice_id = Invoices::latest()->first()->id;
$services = new invoice_services();
$services->invoice_number = $invoice_number;
$services->invoice_id = $invoice_id;
$services->designation = $designation[$i];
$services->QTE = $QTE[$i];
$services->PU = $PU[$i];
$services->total = $QTE[$i] * $PU[$i];
$services->save();
}
..
...
  • Update function : need editing
public function update(Request $request )
{
//Here we need to update the rows !! I tried many ways but it didnt work
}
  • edit function : works well
public function edit($id) { 
$invoices = invoices::where('id', $id)->first();
$services = invoice_services::where('invoice_id' , $id)->get();
$clients = clients::all();
return view('invoices.edit_invoice', compact('clients', 'services' , 'invoices'));
}
  • edit_invoice view : works well
@foreach ($services as $service) 
<tr>
<td><input type="text" name="designation[]" value="" class="form-control"></td>
<td><input type="text" name="QTE[]" id="QTE'+incrementalRow+'" value="" class="form-control"></td>
<td><input type="text" name="PU[]" id="PU'+incrementalRow+'" value="" class="form-control"></td>
<td><input type="text" class="form-control form-control-lg" name="total[]" value="" id="totali'+incrementalRow+'" readonly ></td>
</tr>
@endforeach

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/39WqY6a
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.