Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel collection when

$collection = collect([1, 2, 3]);

$collection->when(true, function ($collection) {
    return $collection->push(4);
});

$collection->all();

// [1, 2, 3, 4]
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #collection
ADD COMMENT
Topic
Name
9+4 =