I am new in Laraver, I am using Eloqunet model... deleteItem function, delete item with offer_in and nbr...When delete item I want to add a new nbr from each item with equal offer_id, starting from 1. I need to define counter = 1, and increase by 1 for every item.. I don't know how to write a for loop, or foreach loop, which pass through selected item, and change 'nbr' with the corresponding value of the counter?
my code is:
public function deleteItem(Request $request, $offer_id, $nbr) {
$item = OfferItem::select('id', 'offer_id', 'nbr', 'product', 'quantity', 'item_price', 'item_tax', 'item_total')
->where('offer_id', $offer_id)
->where('nbr', $nbr)
->first();
$item->delete();
//select new items for offer, after deleting item
$items = OfferItem::select('id', 'offer_id', 'nbr', 'product', 'quantity', 'item_price', 'item_tax', 'item_total')
->where('offer_id', $offer_id)
->get();
//todo
return response()->json($item);
}