| $item_ids = [1, 2, 4]; |
| |
| //simulando itens do resultado do whereIn |
| $items = [ |
| [ |
| "item_id" => 1, |
| "is_available" => true |
| ], |
| [ |
| "item_id" => 2, |
| "is_available" => true |
| ] |
| ]; |
| |
| |
| $itemsFromDB = collect($items); |
| $itemsFromDBPluck = $itemsFromDB->pluck('item_id')->toArray(); |
| |
| collect($item_ids)->map(function ($item) use ($itemsFromDB, $itemsFromDBPluck) { |
| if (!in_array($item, $itemsFromDBPluck)) { |
| $appendItem = [ 'item_id' => $item,'is_avaiable' => false]; |
| $itemsFromDB->push($appendItem); |
| } |
| }); |
| |
| dump($itemsFromDB);//$itemsFromDB->toArray(); |
| |
| |
| |
| collect($item_ids)->map(function ($item) use ($itemsFromDB) { |
| ///dump($item); |
| $findItem = $itemsFromDB->where('item_id',$item); |
| if ($findItem->isEmpty()) { |
| $appendItem = [ 'item_id' => $item,'is_avaiable' => false]; |
| $itemsFromDB->push($appendItem); |
| } |
| }); |
| |
| dump($itemsFromDB);//$itemsFromDB->toArray(); |