Answers for "laravel collection some"

PHP
1

laravel collection methods

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

$collection->each(function($item){
    return $item*$item;
});

// [1,4,9,16]
Posted by: Guest on September-06-2020
0

laravel collection when

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

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

$collection->all();

// [1, 2, 3, 4]
Posted by: Guest on July-24-2021
0

laravel collection where

$collection = collect([
    ['product' => 'Desk', 'price' => 200],
    ['product' => 'Chair', 'price' => 100],
    ['product' => 'Bookcase', 'price' => 150],
    ['product' => 'Door', 'price' => 100],
]);

$filtered = $collection->where('price', 100);

$filtered->all();

/*
    [
        ['product' => 'Chair', 'price' => 100],
        ['product' => 'Door', 'price' => 100],
    ]
*/
Posted by: Guest on July-24-2021
0

laravel collection all

collect([1, 2, 3])->all();

// [1, 2, 3]
Posted by: Guest on July-24-2021

Code answers related to "laravel collection some"

Browse Popular Code Answers by Language