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

laravel collection concat

$collection = collect(['John Doe']);

$concatenated = $collection->concat(['Jane Doe'])->concat(['name' => 'Johnny Doe']);

$concatenated->all();

// ['John Doe', 'Jane Doe', 'Johnny Doe'] 
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 :: explode example in php 
Php :: session_start cookie lifetime 
Php :: laravel model with migration 
Php :: laravel create model controller and migration on line 
Php :: TRANSACTON LARAVEL QUERY BUILDER 
Php :: laravel collective form include image 
Php :: sub menu for post type in wordpress 
Php :: laravel custom validation message 
Php :: phpmyadmin centos 8 
Php :: include() in php 
Php :: php.hello 
Php :: set posts_per_page 
Php :: check if checkbox is not checked laravel 8 
Php :: pdf watermark dengan laravel 
Php :: laravel latest from relationship 
Php :: php add variable to array 
Php :: How To Unset Or Delete An Element From Array By Value In PHP? 
Php :: how to trim string in laravel 
Php :: write string variable in php 
Php :: route laravel Target class [AuthController] does not exist 
Php :: check the request type in laravel 
Php :: laravel local scope 
Php :: remove the last character from a string in php 
Php :: filter var php function 
Php :: author page url from the current post 
Php :: php get all array keys in json 
Php :: install php unzip 
Php :: Undefined constant "STDOUT" in php 
Php :: EntityManager get repository 
Php :: Remove prefix on category title 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =