// From PHP 7.4, you can use the spread syntax to merge arrays in PHP like JavaScript
$firstArray = ['a' => 'life', 'b' => 'ball'];
$secondArray = ['c' => 'History'];
$thirdArray = [...$firstArray, ...$secondArray];
// you can still use the array_merge function
$thirdArray = array_merge($firstArray, $secondArray);
$foo = collect(Foo::all());
$bar = collect(Bar::all());
$merged = $foo->merge($bar);
Arr::add()
The Arr::add method adds a given key / value pair to an array if the given key doesn't already exist in the array or is set to null:
use IlluminateSupportArr;
$array = Arr::add(['name' => 'Desk'], 'price', 100);
// ['name' => 'Desk', 'price' => 100]
$array = Arr::add(['name' => 'Desk', 'price' => null], 'price', 100);
// ['name' => 'Desk', 'price' => 100]