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

laravel collection combine

$collection = collect(['name', 'age']);

$combined = $collection->combine(['George', 29]);

$combined->all();

// ['name' => 'George', 'age' => 29]
Comment

PREVIOUS NEXT
Code Example
Php :: query relationships laravel and select some columns 
Php :: php for next loop step 
Php :: create migration with model laravel 
Php :: wordpress get category description 
Php :: insert multiple rows laravel 
Php :: php write to standard out 
Php :: replace exact word in php 
Php :: how to loop with while in php for array associative 
Php :: laravel check if email is real 
Php :: how to read from temp files php 
Php :: php hello world program 
Php :: add custom post type wordpress 
Php :: php get screen size 
Php :: wp order archive page post by title 
Php :: cors error angular php 
Php :: function in php 
Php :: carbon create from format 
Php :: PHP strtoupper — Make a string uppercase 
Php :: laravel swagger install 
Php :: Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead. 
Php :: laravel foreach loop index in controller 
Php :: php remove element from array by value 
Php :: ziparchive php example 
Php :: file put contents php 
Php :: drupal 9 guzzle client increase timeout 
Php :: phpexcel set row height 
Php :: javascript function in php json_encode 
Php :: Set a minimum subtotal amount in Woocommerce cart 
Php :: Advanced Custom Fields get sub field image 
Php :: codeigniter 4 delete redirect with data 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =