I have a 2d array input like this:
[ 6 => [ [2=>3, 5=>7] ],
8 => [ [1=>4, 9=>3] ],
.....
]
The 6,8 are locationIDs and 2,5,1,9 are variantIDs and 3,4,7,3 are their respective quantities. I have to loop through the 2d array and get the data. The table has the fields location_id, variant_id and quantity.
$variantsData = self::where(function ($query) use ($inventoryData) {
foreach ($inventoryData as $location => $variantData) {
foreach ($variantData as $variant => $quantity) {
$query->orWhere(function ($query) use ($location, $variant) {
$query->where('location_id', $location)
->where('variant_id', $variant);
});
}
}
})->get();
The $inventoryData is the 2d array. I get the data required in this code but now I need to update the quantity by adding the stored quantity with this one in the array.