Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel merge collections

/* 
 * The merge method merges the given array or collection with the original collection.
 * If a string key in the given items matches a string key in the original collection,
 * the given items's value will overwrite the value in the original collection:
 */
$collection = collect(['product_id' => 1, 'price' => 100]);
$merged = $collection->merge(['price' => 200, 'discount' => false]);
$merged->all(); // ['product_id' => 1, 'price' => 200, 'discount' => false]

// If the given items's keys are numeric, the values will be appended to the end of the collection:
$collection = collect(['Desk', 'Chair']);
$merged = $collection->merge(['Bookcase', 'Door']);
$merged->all(); // ['Desk', 'Chair', 'Bookcase', 'Door']
Comment

Merge Two Collection ( Laravel )

$foo = collect(Foo::all());
$bar = collect(Bar::all());
$merged = $foo->merge($bar);

Comment

merge collections laravel

$collection = collect(['product_id' => 1, 'price' => 100]);

$merged = $collection->merge(['price' => 200, 'discount' => false]);

$merged->all();

// ['product_id' => 1, 'price' => 200, 'discount' => false]
Comment

PREVIOUS NEXT
Code Example
Php :: how to prompt user for input in php 
Php :: upload file in php 
Php :: utf8 php 
Php :: how to make db seeder in laravel 
Php :: iterating rows in php 
Php :: create a modal livewire laravel 
Php :: array unique php 
Php :: php append element to array 
Php :: php iterate thru object 
Php :: php link to page 
Php :: Modes of file reading php 
Php :: unset by key name php 
Php :: Clear php cache 
Php :: php add property to object 
Php :: php try catch 
Php :: string to boolean php 
Php :: change key value laravel map collection 
Php :: comparing floats php 
Php :: sum of the array elements in php 
Php :: laravel online hash password generator 
Php :: php laravel between dates 
Php :: Wordpress admin settings form 
Php :: symfony see all make commands 
Php :: web api return json example in php 
Php :: hide env file in laravel 
Php :: Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1 
Php :: Generating Random String In PHP Using uniqid() function 
Php :: woocommerce add to cart hook 
Php :: hello world in php 
Php :: php curl request 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =