samedi 22 juin 2019

How to loop input field value and insert to its row based on the database value in Laravel?

My problem is that I want to update the quantity_served based on quantity and insert the last loop value into the last record based on the input value.

Current Database record

For example, my input value has 180.

Expected Result

My code doesn't insert the last value of loop instead of the full value of quantity.

$var = $request->get('id');
$data = bulkcorporatemodel::orderBy('id', 'asc');

foreach ($data as $item)
{
    if ($var == 0 || $var < 0)
    {
        break;
    }

    $bulkcorp = bulkcorporatemodel::find($item->id);
    $dummyHolder = $bulkcorp->quantity;
    $bulkcorp->quantity_served = $dummyHolder;
    $bulkcorp->save();

    $success_output = '<div class="alert alert-success">BULK DATA UPDATED</div>';
    $var = $var - $dummyHolder;
} 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire