Laravel - Collections - Method Union

The union method adds the given array to the collection. If the given array contains keys that are already in the original collection, the original collection's values will be preferred:

    
    $collection = collect([1 => ['a'], 2 => ['b']]);
    
    $union = $collection->union([3 => ['c'], 1 => ['d']]);
    
    $union->all();
    
    // [1 => ['a'], 2 => ['b'], 3 => ['c']]