Reputation: 29
I am using a form where it sends array data to the controller. and It also received array data like this
$product_unit = $inputs['orderProducts'];
but prob is when i pass this data through foreach loop for matching other products it just show one single array.
foreach ($product_unit as $unit){
$product = Product::all()
->where('id', '=', $unit['product_id'])
->where('unit', '>=', $unit['quantity'])
->first();
}
Here i Want to match received array data to existing product that are inserted. If it matched existing data it will be increment. But here it can only pass single array. Thats why its just increse one row value. Specially Last matched value is incresed. So How can that array data through loop by where function in laravel.
Upvotes: 1
Views: 1986
Reputation: 5270
You have to use like below.
$product= array();
foreach ($product_unit as $unit){
$product[] = Product::all()
->where('id', '=', $unit['product_id'])
->where('unit', '>=', $unit['quantity'])
->first();
}
dd($product)
Upvotes: 1