Answers for "laravel collection combine"

PHP
3

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]
Posted by: Guest on June-06-2020
0

laravel collection concat

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

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

$concatenated->all();

// ['John Doe', 'Jane Doe', 'Johnny Doe']
Posted by: Guest on July-24-2021
0

laravel collection combine

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

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

$combined->all();

// ['name' => 'George', 'age' => 29]
Posted by: Guest on July-24-2021

Code answers related to "laravel collection combine"

Browse Popular Code Answers by Language